菜鸟提问:关于webservice的数据连接

gugu1981 2006-07-26 09:18:43
小弟初学webservice,请各位大虾指点一下。呵呵

调用webservice时候连接数据库时报错:System.Web.Services.Protocols.SoapException: Server was unable to process request. ---> System.Data.SqlClient.SqlException: An error has occurred while establishing a connection to the server. When connecting to SQL Server 2005, this failure may be caused by the fact that under the default settings SQL Server does not allow remote connections.

但是单独调用webservice的asmx文件测试时候,都可以通过的。
调用的代码很简单:
private Hotel.Service ser;
private CTSCHotel ser1;
ser = new Hotel.Service();
ser1 = ser.getHotelByHtlId(99064);
跟踪后发现在SqlConnection对象的open方法报错

webservice部分代码:
[WebService(Namespace = "Hotel")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
public class Service : System.Web.Services.WebService
{
public Service () {

//Uncomment the following line if using designed components
//InitializeComponent();
}

[WebMethod]
public string HelloWorld() {
return "Hello World";
}

[WebMethod]
public CTSCHotel getHotelById(int Id)
{
CTSCHotel test = new CTSCHotel();
test.getHotelById(Id);
return test;
}

[WebMethod]
public CTSCHotel getHotelByHtlId(int htlId)
{
CTSCHotel test = new CTSCHotel();
test.getHotelByHtlId(htlId);
return test;
}
...全文
204 8 打赏 收藏 转发到动态 举报
写回复
用AI写文章
8 条回复
切换为时间正序
请发表友善的回复…
发表回复
sbsrg3000 2006-07-26
  • 打赏
  • 举报
回复
没用过2005....
gugu1981 2006-07-26
  • 打赏
  • 举报
回复
Up
gugu1981 2006-07-26
  • 打赏
  • 举报
回复
up
gugu1981 2006-07-26
  • 打赏
  • 举报
回复
连接字符串没有问题啊。在webservice那个工程里面都可以打开的
丰云 2006-07-26
  • 打赏
  • 举报
回复
所谓的open方法就是连接问题,sql2005对安全检查要求很严,你还是调试你的连接字符串吧
forever9918 2006-07-26
  • 打赏
  • 举报
回复
the default settings SQL Server does not allow remote connections
fanliang11 2006-07-26
  • 打赏
  • 举报
回复
SqlConnection 是否已经打开,或者连接的数据库是否出错
把错误信息贴出来
chouer523 2006-07-26
  • 打赏
  • 举报
回复
不明白你的意思 你可以說得清楚店嗎

62,046

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术交流专区
javascript云原生 企业社区
社区管理员
  • ASP.NET
  • .Net开发者社区
  • R小R
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

.NET 社区是一个围绕开源 .NET 的开放、热情、创新、包容的技术社区。社区致力于为广大 .NET 爱好者提供一个良好的知识共享、协同互助的 .NET 技术交流环境。我们尊重不同意见,支持健康理性的辩论和互动,反对歧视和攻击。

希望和大家一起共同营造一个活跃、友好的社区氛围。

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