webservice:同样的连接字符串,为什么在 asp.net 下正常,而 webservice 中却提示错误?(sqlserver 2000)
在 asp.net 下,建立一个数据访问与输出的类SqlDAL.cs,首先,定义connectionString:
protected static string connectionString =System.Configuration.ConfigurationManager.AppSettings["ConnectionString"];
<方法...>
web.config 配置 ConnectionString:
<appSettings>
<add key="ConnectionString" value="server=192.168.1.1;database=shop;uid=sa;pwd=*"/>
</appSettings>
页面可以访问与输出。
在 webservice 下,如法炮制.
新建 test.asmx,在test.cs 中添加一个方法(访问数据库用来输出数据)。当点击 "调用"后,页面提示出错:
=======================================
System.Data.SqlClient.SqlException: 在建立与服务器的连接时出错。在连接到 SQL Server 2005 时,在默认的设置下 SQL Server 不允许进行远程连接可能会导致此失败。 (provider: SQL 网络接口, error: 25 - 连接字符串无效)
在 System.Data.SqlClient.SqlInternalConnection.OnError(SqlException exception, Boolean breakConnection)
在 System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj)
在 System.Data.SqlClient.TdsParser.Connect(Boolean& useFailoverPartner, Boolean& failoverDemandDone, String host, String failoverPartner, String protocol, SqlInternalConnectionTds connHandler, Int64 timerExpire, Boolean encrypt, Boolean trustServerCert, Boolean integratedSecurity, SqlConnection owningObject, Boolean aliasLookup)
在 System.Data.SqlClient.SqlInternalConnectionTds.OpenLoginEnlist(SqlConnection owningObject, SqlConnectionString connectionOptions, String newPassword, Boolean redirectedUserInstance)
在 System.Data.SqlClient.SqlInternalConnectionTds..ctor(DbConnectionPoolIdentity identity, SqlConnectionString connectionOptions, Object providerInfo, String newPassword, SqlConnection owningObject, Boolean redirectedUserInstance)
在 System.Data.SqlClient.SqlConnectionFactory.CreateConnection(DbConnectionOptions options, Object poolGroupProviderInfo, DbConnectionPool pool, DbConnection owningConnection)
在 System.Data.ProviderBase.DbConnectionFactory.CreatePooledConnection(DbConnection owningConnection, DbConnectionPool pool, DbConnectionOptions options)
在 System.Data.ProviderBase.DbConnectionPool.CreateObject(DbConnection owningObject)
在 System.Data.ProviderBase.DbConnectionPool.UserCreateRequest(DbConnection owningObject)
在 System.Data.ProviderBase.DbConnectionPool.GetConnection(DbConnection owningObject)
在 System.Data.ProviderBase.DbConnectionFactory.GetConnection(DbConnection owningConnection)
在 System.Data.ProviderBase.DbConnectionClosed.OpenConnection(DbConnection outerConnection, DbConnectionFactory connectionFactory)
在 System.Data.SqlClient.SqlConnection.Open()
=============================================
很纳闷:我连接的数据库为sqlserver 2000,为什么提示 “连接到 SQL Server 2005 ”,我根本就没装 SQL Server 2005 啊,所以“连接字符串无效”就很正常了。
搞不懂为什么会这样提示?望解答,谢谢!
在线等!