Reputation: 11
I am new to C#, so forgive me for asking. I am trying to write a SqlConnection
but the following code shows a red scribbly line where the db path begins. I have already copied the path from the database's connection string. It has given me lots of headache. Any help will be greatly appreciated.
SqlConnection con = new SqlConnection(@"Data Source=(LocalDB)\MSSQLLocalDB;AttachDbFilename="D:\projects\Clinic POS\Clinic POS\Inventory.mdf";Integrated Security=True");
Upvotes: 0
Views: 89
Reputation: 186
SqlConnection con = new SqlConnection("Data Source=(LocalDB)\\MSSQLLocalDB;AttachDbFilename=D:\\projects\\Clinic POS\\Clinic POS\\Inventory.mdf;Integrated Security=True");
Upvotes: 0
Reputation: 13450
You should remove the quotes around the file name:
SqlConnection con = new SqlConnection(@"Data Source=(LocalDB)\MSSQLLocalDB;AttachDbFilename=D:\projects\Clinic POS\Clinic POS\Inventory.mdf;Integrated Security=True");
Upvotes: 1