首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > .NET > C# >

ConnectionString 属性尚无初始化

2011-12-24 
ConnectionString 属性尚未初始化。我在web.config中配置了链接字符串connectionStringsaddname OTsof

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);
}
}
.
.......

热点排行