|
Use strConn in SqlConnection myconn = new SqlConnection (strConn);
"Server = ZEMU-A12\COMPANY; UID = zbr; PWD = # szzemucompany #; Database = dbok" instead of running without problems, but if you read <add key = "strConnString" value = "Server = ZEMU-A12\COMPANY ; UID = zbr; PWD = # szzemucompany #; Database = dbok "> </ add> When the value of strConnString is reported, an" instance failed "error is reported, ask the reason
protected static string strConn = System.Configuration.ConfigurationManager.AppSettings ["strConnString"];
public static int ExecuteSql (string strSql)
{
SqlConnection myconn = new SqlConnection (strConn);
SqlCommand mycomm = new SqlCommand (strSql, myconn);
try
{
myconn.Open ();
mycomm.ExecuteNonQuery ();
return 0;
}
catch (System.Data.SqlClient.SqlException e)
{
throw new Exception (e.Message);
}
finally
{
mycomm.Dispose ();
myconn.Close ();
}
}
Web.Config file contents:
<? xml version = "1.0" encoding = "utf-8"?>
<configuration>
<appSettings>
<add key = "strConnString" value = "Server = ZEMU-A12\COMPANY; UID = zbr; PWD = # szzemucompany #; Database = dbok"> </ add>
<add key = "WebSiteVersion" value = "Ver1.0"> </ add>
<add key = "WebManger" value = "Windxf"> </ add>
</ appSettings>
</ configuration> |
|