.net连接到SQL Server数据库

问题描述:

我在本地PC上设置了ASP.NET MVC。我在SQL Server Management Studio中设置了一个数据库,并在web.config中设置连接字符串。当我转到VS2015中的服务器资源管理器时,我可以在我的数据连接中看到数据库。但是,如果我火起来的网站,并尝试注册一个用户,我得到以下错误:.net连接到SQL Server数据库

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)

我知道该字符串是正确的,因为我可以在VS2015

看到它在数据连接我web.config如下:

<entityFramework> 
    <defaultConnectionFactory 
      type="System.Data.Entity.Infrastructure.SqlConnectionFactory, 
EntityFramework" /> 
    <providers> 
     <provider invariantName="System.Data.SqlClient" 
        type="System.Data.Entity.SqlServer.SqlProviderServices, 
EntityFramework.SqlServer" /> 
    </providers> 
</entityFramework> 
<connectionStrings> 
    <add name="ForexRebatesNowDBEntities" 
     connectionString="metadata=res://*/Models.ForexRebatesNowEntities.csdl|res://*/Models.ForexRebatesNowEntities.ssdl|res://*/Models.ForexRebatesNowEntities.msl;provider=System.Data.SqlClient;provider 
connection string=&quot;data source=MSIBEEDGE;initial 
catalog=ForexRebatesNowDB;persist security info=True;user 
id=sa;password=********;MultipleActiveResultSets=True;App=EntityFramework&quot;" 
     providerName="System.Data.EntityClient" />  
</connectionStrings> 

这让我感到沮丧!我无法理解应用程序无法写入SQL Server的方式

+0

尝试使用SQL Server而不是名称的IP地址。您的SQL Server必须设置为允许远程连接。 – logixologist

+0

尝试从本地连接到SQL Server Management Studio。这对你来说是一个很好的指示。 – logixologist

+0

将服务器资源管理器中的连接字符串与web.config中的连接字符串进行比较,看看有什么不同。 – user2773289