ConnectionString 属性尚未初始化。
我在web.config中配置了链接字符串
<connectionStrings>
<add name= "OTsoftConnectionString " connectionString= "Data Source=172.15.0.30;Initial Catalog=OTsoft;User ID=sa;Password=otsoft " providerName= "System.Data.SqlClient " />
</connectionStrings>
然后我定义了一个类
public class DataConnection
{
public string sysconnstring = ConfigurationSettings.AppSettings[ "tetweb_zjsysConnectionString "];
public SqlConnection stoCon;
public DataConnection()
{
sysCon=new SqlConnection (sysconnstring);
}
}
在另一个类中定义
public System.Data .DataTable GetTable(SqlConnection myCon,string SqlState)
{
System.Data .DataTable myTable=new System.Data .DataTable();
try
{
myCon.Open ();
SqlDataAdapter myAdapter=new SqlDataAdapter (SqlState,myCon);
myAdapter.Fill(myTable);
myAdapter.Dispose ();
}
catch(Exception MyInf)
{
throw MyInf;
}
finally
{
myCon.Close ();
}
return myTable;
}
我在.cs中调用这两个类,结果类老是出现“ConnectionString 属性尚未初始化。”的错误
------解决方案--------------------public string sysconnstring = ConfigurationSettings.AppSettings[ "tetweb_zjsysConnectionString "];
public SqlConnection stoCon;
public DataConnection()
{
sysCon=new SqlConnection (sysconnstring);
}
----->
public SqlConnection stoCon;
public DataConnection()
{
sysCon=new SqlConnection (ConfigurationSettings.AppSettings[ "tetweb_zjsysConnectionString "]);
}
------解决方案-------------------- <connectionStrings>
<add key= "connectionString " value= "Data Source=172.15.0.30;Initial Catalog=OTsoft;User ID=sa;Password=otsoft "/>
</connectionStrings>
然后我定义了一个类
public class DataConnection
{
public string sysconnstring = ConfigurationSettings.AppSettings[ "connectionString "];
public SqlConnection stoCon;
public DataConnection()
{
sysCon=new SqlConnection (sysconnstring);
}
}
.
.......