Note that there are some explanatory texts on larger screens.

plurals
  1. POConnect to SQL Server 2008 Database via C#
    primarykey
    data
    text
    <p>I am attempting to connect to a database I created in SQL Server 2008 on my computer. I have a Windows Authentication login which looks like this:</p> <pre><code>try { string sCon = @"Data Source=David-PC\SQLEXPRESS; Initial Catalog=ZarTrackDB; Integrated Security = true"; SqlConnection dbConn; dbConn = new SqlConnection(sCon); dbConn.Open(); } catch (Exception ex) { MessageBox.Show(this, "An error occurd while attemtpting to connect to DB.\n" + ex.Message, "DB Connection Error", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } </code></pre> <p>however it keeps throwing an exception:</p> <blockquote> <p>Login failed for user David-PC\David</p> </blockquote> <p>I am able to connect to the Master DB though:</p> <pre><code> string sCon = @"Data Source=David-PC\SQLEXPRESS; Initial Catalog=Master; Integrated Security = true"; </code></pre> <p>So i guess the probelm might be I do not have permissions? How do I go about giving myslef permissions to access this DB though when I login via SQL Server Management Studio I can insert create query etc on the ZarTrackDB perfectly.</p> <p>I truly dont know what to do anymore please help!</p> <p>EDIT:</p> <p>here is a screen shot of my user mappings for the account I am trying to log in with:</p> <p><strong>User Mappings:</strong></p> <p><img src="https://i.stack.imgur.com/pyVC7.png" alt="enter image description here"></p> <p><strong>Server Roles</strong>:</p> <p><img src="https://i.stack.imgur.com/Ua5NL.png" alt="enter image description here"></p> <p>UPDATE:</p> <p>If I login to master and attempt to access ZarTrack :</p> <pre><code> string sCon = @"Data Source=David-PC\SQLEXPRESS; Initial Catalog=Master; Integrated Security = true"; SqlConnection dbConn; dbConn = new SqlConnection(sCon); dbConn.Open(); string sql = "USE ZarTrackDB "+ "CREATE TABLE Customers ("+ "CustomerID int IDENTITY PRIMARY KEY NOT NULL," + "CompanyName varchar(30) NOT NULL,"+ "CompanyAddress varchar(40) NOT NULL,"+ "Email varchar(40) NOT NULL,"+ "PhoneNumber varchar(15) NOT NULL"+ ");"; SqlCommand dbCmd = new SqlCommand(); dbCmd.CommandText = sql; dbCmd.Connection = dbConn; dbCmd.ExecuteNonQuery(); </code></pre> <p>I get Exception:</p> <p><img src="https://i.stack.imgur.com/Rxlgn.png" alt="enter image description here"></p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload