[英]Error with App.config connectionstrign in class library
I have an error with connection string in class library project. 我在类库项目中的连接字符串有错误。 In Appconfig I have this code:
在Appconfig中,我有以下代码:
<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? 我能做什么?
您可以使用appSettings作为替代选项。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.