I’m fairly new to c# and just now started working with databases. I made a local database in my project folder, when I click properties on the database I get “Connection string” as:
Data Source="C:\Users\Documents\Visual Studio 2012\Projects\DataBaseTest\MyDatabase#1.sdf"
My question is simple, how do I create a connection string using that line? cause writing this generates an error for some reason.
SqlConnection con = new SqlConnection(Data Source="C:\Users\Documents\Visual Studio
2012\Projects\DataBaseTest\MyDatabase#1.sdf");
You are using a SQL Server Compact edition database and for that you must use
SqlCeConnectioninstead ofSqlConnection(Which is used for SQL Server).You must also escape the back backslashes in your connection string
\becomes this\\:or use a verbatim string :
And if you don’t have the necessary libs for using SqlCe in your projects refer to my other answer here :