连接字符串放到配置文件中,会出现未将对象引用设置到对象的实例,求大神帮忙,急急急!!!
连接字符串放到配置文件中,会出现未将对象引用设置到对象的实例//这步主要是将连接字符串放到配置文件中时,用这表达
string connStr = ConfigurationManager.ConnectionStrings["ConnStr"].ConnectionString;运行到这,会出现未将对象引用设置到对象的实例
using (SqlConnection conn = new SqlConnection(connStr))
{
conn.Open();
using (SqlCommand cmd = conn.CreateCommand())
{
= "delect from IP_table";
cmd.ExecuteNonQuery();
}
}
配置文件设置:
<configuration>
<connectionStrings>
<add name="ConnStr" connectionString="Server =.\SQLEXPRESS;AttachDBFilename
=C:\USERS\ADMINISTRATOR\DESKTOP\C\手机IP查询\手机IP查询\手机IP查询\DATABASE1.MDF;
Integrated Security =true;User instance = true"/>
</connectionStrings>
</configuration>