In my winform project, I have a connection string to connect to SQL. I have this connection in the app.config file as follows:
<connectionStrings>
<add name="MyConnectionString" providerName="System.Data.SqlClient"
connectionString="Server=(localdb)\\v11.0; Integrated Security=true; AttachDbFileName=C:\\Folder\\mydataBaseName.mdf;Connect Timeout=15;Encrypt=False;TrustServerCertificate=False"
/>
and I get the connection:
string config = ConfigurationManager.ConnectionStrings["MyConnectionString"].ConnectionString;
using (SqlConnection conexao = new SqlConnection(config))
{
conexao.Open();
.......
.......
}
When I launch the application, I get an error: "An unhandled exception of type" System.Data.SqlClient.SqlException "occurred in System.Data.dll"
But if I call the connection string directly from the code (without using app.config), everything is fine.
string config = "Server=(localdb)\\v11.0; Integrated Security=true; AttachDbFileName=C:\\Folder\\mydataBaseName.mdf;Connect Timeout=15;Encrypt=False;TrustServerCertificate=False";
Any ideas how to solve the problem?
Thanks Leonor
source
share