2016-10-03 125 views
0

我在本地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

回答