webservice:同样的连接字符串,为什么在 asp.net 下正常,而 webservice 中却提示错误?(sqlserver 2000)

music000 2006-11-13 11:33:37
在 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 啊,所以“连接字符串无效”就很正常了。
搞不懂为什么会这样提示?望解答,谢谢!
在线等!
...全文
244 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
WeiWY 2006-11-20
  • 打赏
  • 举报
回复
接分
whu305 2006-11-20
  • 打赏
  • 举报
回复
接分
恭喜楼主
股神 2006-11-20
  • 打赏
  • 举报
回复
up
潜水员2099 2006-11-14
  • 打赏
  • 举报
回复
^_^
music000 2006-11-13
  • 打赏
  • 举报
回复
好了,找出来了,连接字符串确实不小心写错了,粗心大意啊:
把 value 中的一个 “;” 写成了“,”。
汗!
liujia_0421 2006-11-13
  • 打赏
  • 举报
回复
Good..
mmens 2006-11-13
  • 打赏
  • 举报
回复
:)

12,162

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 Web Services
社区管理员
  • Web Services社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧