我的 中有一个connectionstring
,web.config
我正在尝试从class
文件中调用它。
为什么它无法到达数据库。数据库位于项目内部的本地计算机上。
班上
public static SqlConnection createConnection()
{
SqlConnection con = new SqlConnection(ConfigurationManager.AppSettings["Database"]);
con.Open();
return con;
}
和 web.config
<connectionStrings>
<add connectionString="server=.\SQLEXPRESS;uid=The_Kettle_LibraryU;pwd=-5$G)dO:}B7X;Database=The_Kettle_Library" name="Database" providerName="System.Data.SqlClient" />
</connectionStrings>
发布的错误。
Compilation Error
Description: An error occurred during the compilation of a resource required to service this request. Please review the following specific error details and modify your source code appropriately.
Compiler Error Message: CS1502: The best overloaded method match for 'System.Data.SqlClient.SqlConnection.SqlConnection(string)' has some invalid arguments
Source Error:
Line 11: public static SqlConnection createConnection()
Line 12: {
Line 13: SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["Database"]);
Line 14: con.Open();
Line 15: return con;