2017-03-08 51 views
1

我一直在嘗試爲我的ASP.NET Core應用程序安裝SQL Server 2016 Express實例。我已經達到了可以用我的本地開發機器上的開發版連接到數據庫的地步,但是沒有在服務器上發佈的版本(也在託管SQL Server實例)無法從本地服務器訪問數據庫,但可以從遠程服務器

我會將本地開發版本稱爲「開發服務器」,將遠程發佈版本稱爲「真實服務器」。這兩種服務器訪問同一個SQL Server實例

在開發服務器我沒有問題,用下面的connectionString SQL服務器在我appSettings.json

Data Source=10.50.70.50;Integrated Security=False;User ID=voetbal;Password=*******;Connect Timeout=15;Encrypt=False;TrustServerCertificate=True;ApplicationIntent=ReadWrite;MultiSubnetFailover=False 

連接當我嘗試從真實服務器我連接得到的錯誤

SqlException: 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: 52 - Unable to locate a Local Database Runtime installation. Verify that SQL Server Express is properly installed and that the Local Database Runtime feature is enabled.) On the remote machine I've tried the following connectionStrings in both appsettings.json and as an environment variable:

隨着IP:

Data Source=10.50.70.50;Integrated Security=False;User ID=voetbal;Password=*****;Connect Timeout=15;Encrypt=False;TrustServerCertificate=True;ApplicationIntent=ReadWrite;MultiSubnetFailover=False 

隨着本地主機而不是IP:

Data Source=localhost;Integrated Security=False;User ID=voetbal;Password=*****;Connect Timeout=15;Encrypt=False;TrustServerCertificate=True;ApplicationIntent=ReadWrite;MultiSubnetFailover=False 

隨着本地機器名:

Data Source=WIN-DMM50393I9A;Integrated Security=False;User ID=voetbal;Password=*****;Connect Timeout=15;Encrypt=False;TrustServerCertificate=True;ApplicationIntent=ReadWrite;MultiSubnetFailover=False 

隨着本地機器名和SQL實例名稱:

Data Source=WIN-DMM50393I9A\MSSQLLOCALDB;Integrated Security=False;User ID=voetbal;Password=*****;Connect Timeout=15;Encrypt=False;TrustServerCertificate=True;ApplicationIntent=ReadWrite;MultiSubnetFailover=False 

作爲的LocalDB:

Data Source=(localdb)\\MSSQLLOCALDB;Integrated Security=False;User ID=voetbal;Password=*****;Connect Timeout=15;Encrypt=False;TrustServerCertificate=True;ApplicationIntent=ReadWrite;MultiSubnetFailover=False 

然後我想,m aybe它應該是「服務器」而不是「數據源」,所以我再次嘗試了這些替換。還是一樣的錯誤。

所以有些東西告訴我連接字符串不是這裏的問題。每當我在因特網上搜索錯誤時,我只能找到關於試圖連接到實際LocalDB實例而不是SQL Server Express實例的人員的帖子。如果我的應用程序確實試圖連接到LocalDB實例,那麼爲什麼我的開發人員服務器使用數據庫?

我不知道我能做些什麼來解決這個問題。有任何想法嗎?

回答

1

您確定您已爲這兩種環境定義了ConnectionString:DEV和Production,關於appsettings.Development.json和appsettings.json?

你能嘗試登錄服務器上的連接字符串值:

string conectionString = Configuration.GetConnectionString("DefaultConnection"); 
+0

爲了測試我只使用appsettings.json,它不受環境的具體appsettings.json文件 –

+0

請再次解釋重寫。當您嘗試從本地機器連接到託管在「服務器」上的SQL實例時,您遇到問題? –

+0

有我的本地開發機器和一臺服務器機器。服務器機器具有SQL Server Express。當我在本地開發機器上運行我的asp.net應用程序時,應用程序可以連接到SQL Server。當我在服務器機器上運行應用程序時,該應用程序無法連接到SQL Server。 –

相關問題