调试运行出现以下错误“/图书销售系统”应用程序中的服务器错误。
--------------------------------------------------------------------------------在建立与服务器的连接时出错。在连接到 SQL Server 2005 时,在默认的设置下 SQL Server 不允许进行远程连接可能会导致此失败。 (provider: SQL 网络接口, error: 25 - 连接字符串无效)
说明: 执行当前 Web 请求期间,出现未处理的异常。请检查堆栈跟踪信息,以了解有关该错误以及代码中导致错误的出处的详细信息。 异常详细信息: System.Data.SqlClient.SqlException: 在建立与服务器的连接时出错。在连接到 SQL Server 2005 时,在默认的设置下 SQL Server 不允许进行远程连接可能会导致此失败。 (provider: SQL 网络接口, error: 25 - 连接字符串无效)源错误:
行 133: {
行 134: SqlConnection myConn = GetConnection();
行 135: myConn.Open();
行 136: SqlCommand myCmd = new SqlCommand();
行 137: myCmd.Connection = myConn;
源文件: c:\源文件\图书销售系统\App_Code\dbclass.cs 行: 135 web.config上的连接字符串:
<connectionStrings>
<add name="ordershopConnectionString" connectionString="server=CWC-CFE8921CD33\\SQLEXPRESS;Initial Catalog=ordershop;Integrated Security=True;database=ordershop;uid=sa,pwd=sa"
providerName="System.Data.SqlClient" />
<add name="ordershopConnectionString2" connectionString="server=CWC-CFE8921CD33\\SQLEXPRESS;Initial Catalog=ordershop;Integrated Security=True;database=ordershop;uid=sa,pwd=sa"
providerName="System.Data.SqlClient" />
<add name="ordershopConnectionString3" connectionString="server=CWC-CFE8921CD33\\SQLEXPRESS;Initial Catalog=ordershop;Integrated Security=True;database=ordershop;uid=sa,pwd=sa"
providerName="System.Data.SqlClient" />
</connectionStrings>
dbclass.cs上的连接:
public SqlConnection GetConnection()
{
string sql = "server=CWC-CFE8921CD33\\SQLEXPRESS,database=ordershop,uid=sa,pwd=sa";
SqlConnection myConn = new SqlConnection(sql);
return myConn;
}还有上面提示错误的地方:
public SqlCommand getcmd(string strSql)
{
SqlConnection myConn = GetConnection();
myConn.Open();
SqlCommand myCmd = new SqlCommand();
myCmd.Connection = myConn;
myCmd.CommandText = strSql;
myCmd.CommandType = CommandType.Text;
return myCmd;
}
--------------------------------------------------------------------------------在建立与服务器的连接时出错。在连接到 SQL Server 2005 时,在默认的设置下 SQL Server 不允许进行远程连接可能会导致此失败。 (provider: SQL 网络接口, error: 25 - 连接字符串无效)
说明: 执行当前 Web 请求期间,出现未处理的异常。请检查堆栈跟踪信息,以了解有关该错误以及代码中导致错误的出处的详细信息。 异常详细信息: System.Data.SqlClient.SqlException: 在建立与服务器的连接时出错。在连接到 SQL Server 2005 时,在默认的设置下 SQL Server 不允许进行远程连接可能会导致此失败。 (provider: SQL 网络接口, error: 25 - 连接字符串无效)源错误:
行 133: {
行 134: SqlConnection myConn = GetConnection();
行 135: myConn.Open();
行 136: SqlCommand myCmd = new SqlCommand();
行 137: myCmd.Connection = myConn;
源文件: c:\源文件\图书销售系统\App_Code\dbclass.cs 行: 135 web.config上的连接字符串:
<connectionStrings>
<add name="ordershopConnectionString" connectionString="server=CWC-CFE8921CD33\\SQLEXPRESS;Initial Catalog=ordershop;Integrated Security=True;database=ordershop;uid=sa,pwd=sa"
providerName="System.Data.SqlClient" />
<add name="ordershopConnectionString2" connectionString="server=CWC-CFE8921CD33\\SQLEXPRESS;Initial Catalog=ordershop;Integrated Security=True;database=ordershop;uid=sa,pwd=sa"
providerName="System.Data.SqlClient" />
<add name="ordershopConnectionString3" connectionString="server=CWC-CFE8921CD33\\SQLEXPRESS;Initial Catalog=ordershop;Integrated Security=True;database=ordershop;uid=sa,pwd=sa"
providerName="System.Data.SqlClient" />
</connectionStrings>
dbclass.cs上的连接:
public SqlConnection GetConnection()
{
string sql = "server=CWC-CFE8921CD33\\SQLEXPRESS,database=ordershop,uid=sa,pwd=sa";
SqlConnection myConn = new SqlConnection(sql);
return myConn;
}还有上面提示错误的地方:
public SqlCommand getcmd(string strSql)
{
SqlConnection myConn = GetConnection();
myConn.Open();
SqlCommand myCmd = new SqlCommand();
myCmd.Connection = myConn;
myCmd.CommandText = strSql;
myCmd.CommandType = CommandType.Text;
return myCmd;
}
string sql = "server=CWC-CFE8921CD33\\SQLEXPRESS,database=ordershop,uid=sa,pwd=sa";
这里面是用分号隔开的,不是用逗号
如果还不行的话,就看一下sql server有没有版本有没有正确,看你这个好像是2005的express版本,如果不是的话,sever要改下,还有账号和密码有没有正确
如果还不行那就是sql server配置有问题了
就不需要string sql = "server=CWC-CFE8921CD33\\SQLEXPRESS,database=ordershop,uid=sa,pwd=sa";连接了用一种就行
--------------------------------------------------------------------------------实例失败。
说明: 执行当前 Web 请求期间,出现未处理的异常。请检查堆栈跟踪信息,以了解有关该错误以及代码中导致错误的出处的详细信息。 异常详细信息: System.InvalidOperationException: 实例失败。源错误: 执行当前 Web 请求期间生成了未处理的异常。可以使用下面的异常堆栈跟踪信息确定有关异常原因和发生位置的信息。 堆栈跟踪:
[InvalidOperationException: 实例失败。]
System.Data.SqlClient.TdsParser.Connect(ServerInfo serverInfo, SqlInternalConnectionTds connHandler, Boolean ignoreSniOpenTimeout, Int64 timerExpire, Boolean encrypt, Boolean trustServerCert, Boolean integratedSecurity, SqlConnection owningObject) +737932
System.Data.SqlClient.SqlInternalConnectionTds.AttemptOneLogin(ServerInfo serverInfo, String newPassword, Boolean ignoreSniOpenTimeout, Int64 timerExpire, SqlConnection owningObject) +114
System.Data.SqlClient.SqlInternalConnectionTds.LoginNoFailover(String host, String newPassword, Boolean redirectedUserInstance, SqlConnection owningObject, SqlConnectionString connectionOptions, Int64 timerStart) +282
System.Data.SqlClient.SqlInternalConnectionTds.OpenLoginEnlist(SqlConnection owningObject, SqlConnectionString connectionOptions, String newPassword, Boolean redirectedUserInstance) +181
System.Data.SqlClient.SqlInternalConnectionTds..ctor(DbConnectionPoolIdentity identity, SqlConnectionString connectionOptions, Object providerInfo, String newPassword, SqlConnection owningObject, Boolean redirectedUserInstance) +173
System.Data.SqlClient.SqlConnectionFactory.CreateConnection(DbConnectionOptions options, Object poolGroupProviderInfo, DbConnectionPool pool, DbConnection owningConnection) +357
System.Data.ProviderBase.DbConnectionFactory.CreatePooledConnection(DbConnection owningConnection, DbConnectionPool pool, DbConnectionOptions options) +30
System.Data.ProviderBase.DbConnectionPool.CreateObject(DbConnection owningObject) +424
System.Data.ProviderBase.DbConnectionPool.UserCreateRequest(DbConnection owningObject) +66
System.Data.ProviderBase.DbConnectionPool.GetConnection(DbConnection owningObject) +494
System.Data.ProviderBase.DbConnectionFactory.GetConnection(DbConnection owningConnection) +82
System.Data.ProviderBase.DbConnectionClosed.OpenConnection(DbConnection outerConnection, DbConnectionFactory connectionFactory) +105
System.Data.SqlClient.SqlConnection.Open() +111
System.Data.Common.DbDataAdapter.FillInternal(DataSet dataset, DataTable[] datatables, Int32 startRecord, Int32 maxRecords, String srcTable, IDbCommand command, CommandBehavior behavior) +121
System.Data.Common.DbDataAdapter.Fill(DataSet dataSet, Int32 startRecord, Int32 maxRecords, String srcTable, IDbCommand command, CommandBehavior behavior) +137
System.Data.Common.DbDataAdapter.Fill(DataSet dataSet, String srcTable) +83
System.Web.UI.WebControls.SqlDataSourceView.ExecuteSelect(DataSourceSelectArguments arguments) +1770
System.Web.UI.WebControls.ListControl.OnDataBinding(EventArgs e) +92
System.Web.UI.WebControls.ListControl.PerformSelect() +31
System.Web.UI.WebControls.BaseDataBoundControl.DataBind() +70
System.Web.UI.WebControls.BaseDataBoundControl.EnsureDataBound() +82
System.Web.UI.WebControls.ListControl.OnPreRender(EventArgs e) +26
System.Web.UI.Control.PreRenderRecursiveInternal() +86
System.Web.UI.Control.PreRenderRecursiveInternal() +170
System.Web.UI.Control.PreRenderRecursiveInternal() +170
System.Web.UI.Control.PreRenderRecursiveInternal() +170
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +2041
我用的是vs 2008和sql server 2005 express,设置上应该是没问题的,会不会是网页对应的数据库本身就是有问题呢?
server=CWC-CFE8921CD33\\SQLEXPRESS,database=ordershop,uid=sa,pwd=sa
这句的逗号,应该是分号哟。
<add name="ordershopConnectionString" connectionString="server=CWC-CFE8921CD33\\SQLEXPRESS;Initial Catalog=ordershop;Integrated Security=True;database=ordershop;uid=sa,pwd=sa"
providerName="System.Data.SqlClient" />
<add name="ordershopConnectionString2" connectionString="server=CWC-CFE8921CD33\\SQLEXPRESS;Initial Catalog=ordershop;Integrated Security=True;database=ordershop;uid=sa,pwd=sa"
providerName="System.Data.SqlClient" />
<add name="ordershopConnectionString3" connectionString="server=CWC-CFE8921CD33\\SQLEXPRESS;Initial Catalog=ordershop;Integrated Security=True;database=ordershop;uid=sa,pwd=sa"
providerName="System.Data.SqlClient" />
</connectionStrings>跟改好以后dbclass.cs下的连接字符串: public SqlConnection GetConnection()
{
string sql = "server=CWC-CFE8921CD33\\SQLEXPRESS;database=ordershop;uid=sa;pwd=sa";
SqlConnection myConn = new SqlConnection(sql);
return myConn;
}不过还是出现我3楼所贴的错误,我用的是XP sp2系统,vs2008,sql server 2005 express edition就是微软官网下载的轻量版,组件有:sql server management studio express;配置工具:sql server
错误和使用情况报告;sql server 配置管理器;sql server 外围应用配置;sql server的配置应该是没问题的,楼上那么多位所提及的,都已经配置到了。请问是不是sql server 版本的问题所造成的呢?如果是那应该安装什么版本,怎么配置?谢谢各位了
少改一个逗号,最后面的。
这种问题一般先看链接字符串,然后是数据库的设置,2005比2000的时候多了几个地方。再就是你可以用2005或2008的新建数据源的方法,让vs帮你建立链接,这个方式一般不会出错,适合对数据库操作的练习。