数据库无法在服务器上访问,但在localhost上运行良好

时间:2012-07-28 10:39:22

标签: asp.net sql-server-2008

我用C#在ASP.NET中开发了我的第一个网站。这是一个小型网站,它使用Microsoft SQL Server 2008作为数据库,我已将其部署在免费托管网站www.somee.com上。它的数据库在我的计算机上运行良好但是当我尝试访问服务器上的数据库时,它会出现以下错误:

[ A network-related or instance-specific error occurred while establishing a 
connection to SQL Server. 
The server was not found or was not accessible. Verify that the instance name is correct and that SQL Server is configured to allow remote connections. 
(provider: SQL Network Interfaces, 
error: 26 - Error Locating Server/Instance Specified)].

我在web.config中更新了数据库的连接字符串,我使用了getConString()方法来访问连接字符串,如下所示:

public string getConString()
{
    return System.Configuration.ConfigurationManager.ConnectionStrings["ConString"].ConnectionString;
}

我该怎么做才能解决这个问题。

Wbsite网址为:www.easyways.somee.com

2 个答案:

答案 0 :(得分:1)

感谢各位的支持。我得到了解决问题的方法。实际上我在创建数据库或使用连接字符串时做错了。

现在我重新创建了一个空白数据库,然后通过导航到“用户 - >托管产品 - > MS SQL - >数据库 - >(数据库名称) - &gt执行我为数据库创建的SQL脚本;来自文件的新SQL查询“。并且还更新了web.config文件中的新连接字符串。

这是我现在使用的连接字符串:

"workstation id=dataeasyways.mssql.somee.com;packet size=4096;user id=easyways_db;pwd=********;data source=dataeasyways.mssql.somee.com;persist security info=False;initial catalog=dataeasyways"

答案 1 :(得分:0)

您的托管服务提供商会为您提供连接信息(如果是您的托管服务提供商,您可以在此处看到他们的Help Page,其中显示了如何连接到他们的数据库。

基本上归结为登录到他们的控制面板。

In "User menu" navigate to "User -> Managed products -> MS SQL -> Databases -> (Database name)".

还要记住,由于这是一个远程数据库,因此很少有机会从外部世界获得它,并且只有本地Web服务器才能访问数据库。

相关问题