Accessing local database created in VS 2005 [modified]
-
I have installed and configured MS SQL 2005 Express. Both SQL Server and SQL Server Browser login set to "Local System", Shared Memory, Named Pipes and all the stuff set correctly. If I want to connect to database created in the SQL Server Management Studio, everything is OK, no User ID or Password needed, because of the trusted connection. Then I've added a database in my project and set Windows Authentication in the "Modify Connection...". After running the program, I've got exception number 4060: Cannot open database "AddressBook" requested by the login. The login failed. Login failed for user ''. This is the connection string I've used: SqlConnection myConnection = new SqlConnection( "server=.\\SQLEXPRESS;" + "Trusted_Connection=yes;" + "database=AddressBook;"); Connection test in VS is also OK, only accessing the database (.mdf) programatically using SqlConnection goes wrong. Maybe it's something easy to fix, but I tried books, Google and MSDN without any progress, so I feel desperate from this :(
-
I have installed and configured MS SQL 2005 Express. Both SQL Server and SQL Server Browser login set to "Local System", Shared Memory, Named Pipes and all the stuff set correctly. If I want to connect to database created in the SQL Server Management Studio, everything is OK, no User ID or Password needed, because of the trusted connection. Then I've added a database in my project and set Windows Authentication in the "Modify Connection...". After running the program, I've got exception number 4060: Cannot open database "AddressBook" requested by the login. The login failed. Login failed for user ''. This is the connection string I've used: SqlConnection myConnection = new SqlConnection( "server=.\\SQLEXPRESS;" + "Trusted_Connection=yes;" + "database=AddressBook;"); Connection test in VS is also OK, only accessing the database (.mdf) programatically using SqlConnection goes wrong. Maybe it's something easy to fix, but I tried books, Google and MSDN without any progress, so I feel desperate from this :(
It sounds like you're trying to work with a detached file, one that isn't a permanently configured database. If that's what you're trying to do, you need to specify the filename in the connection string, using the
AttachDBFilename
keyword. For more information, see the documentation forSqlConnection.ConnectionString
.Stability. What an interesting concept. -- Chris Maunder