The connection string which I have copied from Server Explorer in Visual Studio 2019 is
Data Source=(LocalDB)\\MSSQLLocalDB;AttachDbFilename="C:\\Users\\Lenovo\\Desktop\\dev\\C# .net\\Aadi Paw Plethysmometer\\Aadi Paw Plethysmometer\\bin\\Debug\\Database1.mdf";Integrated Security=True;Connect Timeout=30
Because there are some ""
in the string, the code is returning an error.
This is the code:
string connectionstring =
@"Data Source=(LocalDB)\MSSQLLocalDB;AttachDbFilename="C:\Users\Lenovo\Desktop\dev\C# .net\Aadi Paw Plethysmometer\Aadi Paw Plethysmometer\bin\Debug\Database1.mdf";Integrated Security=True;Connect Timeout=30";
For plain strings escape double quotes with \\"
.
string plain = "Double quote (\").";
For verbatim strings escape double quotes with ""
.
string verbatim = @"Double quote ("").";
Note: it doesn't matter whether it is a connection string or not. From the C# perspective, this is just a string.
string connectionstring =
@"Data Source=(LocalDB)\MSSQLLocalDB;AttachDbFilename=""C:\Users\Lenovo\Desktop\dev\C# .net\Aadi Paw Plethysmometer\Aadi Paw Plethysmometer\bin\Debug\Database1.mdf"";Integrated Security=True;Connect Timeout=30";
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.