Reputation: 159
No matter what I try I keep getting the following error when I try to run a simple select query to the database I created (I've run the exact query in the Management studio and it works fine and the login used is in the sysadmin group):
{"Cannot open database \"Test\" requested by the login. The login failed.\r\nLogin failed for user 'JackLarson'."} System.SystemException {System.Data.SqlClient.SqlException}
My connection string is:
Data Source=.\MPIT_TEST;Initial Catalog=Test;Integrated Security=True;Connect Timeout=30;User Instance=True
Upvotes: 1
Views: 538
Reputation: 3929
you have to set your server name in your connection string if your servername is SERVERSQLCOMPUTER your connection string will be:
Data Source=SERVERSQLCOMPUTER \MPIT_TEST;Initial Catalog=[Test_MPITRACKER];Integrated Security=True;Connect Timeout=30;User Instance=True
Moreover, always specify server name to be able to use your application on every computer in network entreprise (servername\serverinstance is an absolute path) .\serverinstance means that your application is on the same computer than your Sql server
Upvotes: 2
Reputation: 5723
Take a look at the error message. It says it cannot find database named Test although you specified Test_MPITRACKER in the connection string. It looks like there is an issue when you have a database with undescore _
character in its name.
The easiest way would be to remove the undescore from the name of the database.
If you want to use database name with the underscore character, try to wrap it with square brackets, so it looks like this:
Data Source=.\MPIT_TEST;Initial Catalog=[Test_MPITRACKER];Integrated Security=True;Connect Timeout=30;User Instance=True
However, I haven't tested this solution, it's based on information found here: Database created in SQL Server Management Studios cannot be found by Visual Studio 2010.
EDIT
According to the conversation in the comments this is not the cause of the issue in this case.
Upvotes: 0