conn。open()出现connectionstring为初始化
web。config里的内容:<?xml version="1.0"?>
<configuration>
<configSections>
</sectionGroup>
</sectionGroup>
</sectionGroup>
</configSections>
<appSettings/>
<connectionStrings>
<add name="connectionstring" connectionString="Server=win-ho0cs0gr0k6\sqlexpress;database=51aspxCar;User ID=sa;Password=123456;" providerName="System.Data.SqlClient"/>
</connectionStrings>
<system.web>
在index。aspx。cs里的代码:
using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient;
using System.Configuration;
namespace car1
private void login_Click(object sender, System.EventArgs e)
{
//检查帐号和密码
if(this.username.Text=="user"&this.password.Text=="user")
{
Session["S_username"]="";
Response.Redirect("main2.aspx");
}
string SqlConn = System.Configuration.ConfigurationSettings.AppSettings["connectionstring"];
SqlConnection Conn=new SqlConnection(SqlConn);
Conn.Open();
string SqlStr0="select username,userpwd,userrule from [user] where username='"+this.username.Text+"' and userpwd='"+this.password.Text+"' and userrule='普通用户' and part='院办(车队)'";
SqlCommand Comm0=new SqlCommand(SqlStr0,Conn);
SqlDataReader read0=Comm0.ExecuteReader();
if(read0.Read())
有高手可以解决吗 谢谢哦!也可以QQ交流:523061346 --------------------编程问答-------------------- string SqlConn = System.Configuration.ConfigurationSettings.AppSettings["connectionstring"];
读的是AppSettings,配置文件里是在<connectionStrings>
根本不是一个地方 --------------------编程问答-------------------- 明明设置在<connectionStrings>节,
<connectionStrings>
<add name="connectionstring" connectionString="Server=win-ho0cs0gr0k6\sqlexpress;database=51aspxCar;User ID=sa;Password=123456;" providerName="System.Data.SqlClient"/>
</connectionStrings>
你却要从AppSettings节去读 --------------------编程问答-------------------- 老问题了,既然你的Web.Config文件中使用的是connectionString配置节,那你下面也应该用ConnectionString才对。
string SqlConn = System.Configuration.ConfigurationManager.ConnectionStrings["connectionstring"].ConnectionString; --------------------编程问答-------------------- string SqlConn = System.Configuration.ConfigurationSettings.AppSettings["connectionstring"];修改为
string SqlConn =ConfigurationManager.ConnectionStrings["connectionstring"];
--------------------编程问答--------------------
+++++++++ --------------------编程问答-------------------- 上面的是保持你Web.Config文件不修改,修改cs中代码的方法。
下面是保持你cs代码不变,修改Web.Config文件中的内容
<appSettings>
<add key="connectionstring" value="Server=win-ho0cs0gr0k6\sqlexpress;database=51aspxCar;User ID=sa;Password=123456;"/>
</appSettings>
<connectionStrings>
<add name="connectionstring" connectionString="Server=win-ho0cs0gr0k6\sqlexpress;database=51aspxCar;User ID=sa;Password=123456;" providerName="System.Data.SqlClient"/>
</connectionStrings>
问题解决,没有留下QQ的必要。
--------------------编程问答-------------------- 这个问题怎么还有人不懂啊!!你连接数据库为什么要死在一种方法上呢?
static string connectionString = ConfigurationManager.ConnectionStrings["GYDConnectionString"].ConnectionString;
public void IsExistTable(string tablename)
{
SqlConnection SQLConn = new SqlConnection(connectionString);
…………
}
--------------------编程问答--------------------
你用的是AppSettings来获取连接名明显跟你web.config里面配置的不一样 --------------------编程问答-------------------- 如果用AppSettings,在web.config的<configuration>中这样写:
<appSettings>
<add key="connectionstring" value="Server=win-ho0cs0gr0k6\sqlexpress;database=51aspxCar;User ID=sa;Password=123456"/>
</appSettings>
补充:.NET技术 , ASP.NET