当前位置: 代码迷 >> ASP.NET >> System.InvalidOperationException: ConnectionString 属性并未初始化
  详细解决方案

System.InvalidOperationException: ConnectionString 属性并未初始化

热度:4723   发布时间:2013-02-25 00:00:00.0
System.InvalidOperationException: ConnectionString 属性尚未初始化
protected void qrjy_Click(object sender, EventArgs e)
  {
  string tjg = jg.Text;
  string tjs = js.Text;
  string tjyr = jyrq.Text;
  string txj = xj.Text;
  string tbh = bh.Text;
  string tmc = mc.Text;
  string strConn = ConfigurationManager.AppSettings["ctOra"];
  OracleConnection cnn = new OracleConnection(strConn);
  string sql = "insert into deal (jg,js,jyr,xj,bh,mc) values ('" + tjg + "','" + tjs + "','to_date('" + tjyr + "','yyyy-mm-dd')," + txj + "','" + tbh + "','" + tmc + "')";
  OracleCommand cmd = new OracleCommand(sql, cnn);
  cnn.Open();
  cmd.ExecuteNonQuery();
  cnn.Close();
  }





提示说cnn.Open();这里没有初始化






------解决方案--------------------------------------------------------
如下修改看看

string strConn = ConfigurationManager.ConnectionStrings["SqlConnStr"].ConnectionString;
类里面是不是有这个东西

请在web.config中配置sqlconnstr:
<connectionStrings>
<add name="SqlConnStr" connectionString="user id=sa;password=sa;initial catalog=test;data source=192.168.1.101" />
</connectionStrings>
------解决方案--------------------------------------------------------
ConfigurationManager.AppSettings["ctOra"] 你配置里的oracle 连接字符串是啥。
------解决方案--------------------------------------------------------
探讨

引用:
ConfigurationManager.AppSettings["ctOra"] 你配置里的oracle 连接字符串是啥。


string strConn = ConfigurationManager.AppSettings["ctOra"];

------解决方案--------------------------------------------------------
详细请参考:
http://www.connectionstrings.com/oracle
  相关解决方案