In my winform project I have a connection string to connect to SQL. I have this connection in app.config file like this;
<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;
//and then
using (SqlConnection conexao = new SqlConnection(config))
{
conexao.Open();
.......
.......
}
When I run the app I get an error saying : "An unhandled exception of type 'System.Data.SqlClient.SqlException' occurred in System.Data.dll"
But If I call the connection string directlly from code (not using the app.config) everthing is ok .
string config = "Server=(localdb)\\v11.0; Integrated Security=true; AttachDbFileName=C:\\Folder\\mydataBaseName.mdf;Connect Timeout=15;Encrypt=False;TrustServerCertificate=False";
Any ideias, how to solve the problem ?
Thanks Leonor