Click here to Skip to main content
15,892,575 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hi, I'm new to using SQL databases with c#. I have made a database but I cant seem to connect to it. The database is showing in the server explorer under data connections. I have been told to use this...

C#
SqlConnection MyConnection = new SqlConnection("Data Source=|DataDirectory|\\db_core.sdf");

MyConnection.Open();


When I test the connect it responds successful though. Can anyone help? Thanks.
Posted
Updated 21-Oct-12 23:28pm
v2

1 solution

Try This Code......


SqlConnection con=new SqlConnection("Data Source=.\\sqlexpress;Initial Catalog=DatabaseName;Integrated Security=True");

con.Open();
 
Share this answer
 
Comments
Adam92 22-Oct-12 5:57am    
That seems to work a little better, in terms of it finds the database but now tells me the login is incorrect. But I haven't set any credentials? Thanks

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900