Reputation: 93
I have an error with connection string in class library project. In Appconfig I have this code:
<connectionStrings>
<add name="DefaultConnection" connectionString="Data Source=DESKTOP-123\SQLEXPRESS;Initial Catalog=MyDb;User ID=sa;Password=mypassword" providerName="System.Data.SqlClient"/>
</connectionStrings>
Connection string I call form a static function:
public static string ConnDb {
get {
return ConfigurationManager.ConnectionStrings["DefaultConnection"].ConnectionString;
}
}
When I use this connection string in function
Sqlconnection conn = new Sqlconnection(Class1.ConnDb)
I have some error like
{"Object reference not set to an instance of an object."}
What can I do?
Upvotes: 0
Views: 160