本文介绍了使用Web配置文件时连接出错的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
Web配置代码如下
< connectionstrings >
< add name = dbconnection connectionstring = Mymachine \ SQLSERVER2012; Integrated Security = true; Initial Catalog = Testing providername = System.Data.SqlClient / >
< / connectionstrings >
.aspx代码如下
protected void Page_Load(object sender,EventArgs e)
{
if(!IsPostBack)
{
this.BindGrid();
}
}
private void BindGrid()
{
string strConnString = ConfigurationManager.ConnectionStrings [dbconnection ] .ConnectionString;
using(SqlConnection con = new SqlConnection(strConnString))
{
using(SqlCommand cmd = new SqlCommand())
{
cmd.CommandText =select Tb_Employee ;
cmd.Connection = con;
con.Open();
gvEmpdetails.DataSource = cmd.ExecuteReader();
gvEmpdetails.DataBind();
con.Close();
}
}
}
当我运行应用程序时显示如下错误
>不支持关键字:'Mymachine \sqlserver2012;综合保障'
请在上面的代码中出现什么错误
我有什么试过:
网页配置代码如下
< connectionstrings >
< add 名称 = dbconnection connectionstring = Mymachine \ SQLSERVER2012; Integrated Security = true; Initial Catalog = Testing providername = System.Data.SqlClient / >
< / connectionstrings >
protected void Page_Load(object sender,EventArgs e)
{
if(! IsPostBack)
{
this.BindGrid();
}
}
private void BindGrid()
{
string strConnString = ConfigurationManager.ConnectionStrings [dbconnection ] .ConnectionString;
using(SqlConnection con = new SqlConnection(strConnString))
{
using(SqlCommand cmd = new SqlCommand())
{
cmd.CommandText =select Tb_Employee ;
cmd.Connection = con;
con.Open();
gvEmpdetails.DataSource = cmd.ExecuteReader();
gvEmpdetails.DataBind();
con.Close();
}
}
}
.aspx代码如下
< pre lang = HTML >
当我运行应用程序时显示错误如下
>不支持关键字:'Mymachine \sqlserver2012;综合安全'
请在上面的代码中出现什么错误
解决方案
Web config code as follows
<connectionstrings> <add name="dbconnection" connectionstring="Mymachine\SQLSERVER2012; Integrated Security=true; Initial Catalog=Testing" providername="System.Data.SqlClient" /> </connectionstrings>
in .aspx code as follows
protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { this.BindGrid(); } } private void BindGrid() { string strConnString = ConfigurationManager.ConnectionStrings["dbconnection"].ConnectionString; using (SqlConnection con = new SqlConnection(strConnString)) { using (SqlCommand cmd = new SqlCommand()) { cmd.CommandText ="select Tb_Employee"; cmd.Connection = con; con.Open(); gvEmpdetails.DataSource = cmd.ExecuteReader(); gvEmpdetails.DataBind(); con.Close(); } } }
When i run the application shows error as follows
>Keyword not supported: 'Mymachine\sqlserver2012; integrated security'
please what is the mistake in my above code
What I have tried:
Web config code as follows
<connectionstrings> <add name="dbconnection" connectionstring="Mymachine\SQLSERVER2012; Integrated Security=true; Initial Catalog=Testing" providername="System.Data.SqlClient" /> </connectionstrings> protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { this.BindGrid(); } } private void BindGrid() { string strConnString = ConfigurationManager.ConnectionStrings["dbconnection"].ConnectionString; using (SqlConnection con = new SqlConnection(strConnString)) { using (SqlCommand cmd = new SqlCommand()) { cmd.CommandText ="select Tb_Employee"; cmd.Connection = con; con.Open(); gvEmpdetails.DataSource = cmd.ExecuteReader(); gvEmpdetails.DataBind(); con.Close(); } } } in .aspx code as follows <pre lang="HTML">
When i run the application shows error as follows
>Keyword not supported: 'Mymachine\sqlserver2012; integrated security'
please what is the mistake in my above code
解决方案
这篇关于使用Web配置文件时连接出错的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!