2016-12-07 94 views
1

我正在使用Visual Studio 2015.我在Azure上創建了一個數據庫並連接到它,並且可以在SQL對象瀏覽器中看到它連接。將Azure SQL數據庫連接到ASP.NET項目

我已經從Azure儀表板的連接字符串中複製並設置數據庫的防火牆,以允許任何IP地址訪問數據庫。

我的連接字符串是:

static string connString = @"Server=tcp:uvaluedb2.database.windows.net,1433;Initial Catalog=UValueDB2;Persist Security Info=False;User ID=XXXXXXX;Password=XXXXXXXXX;MultipleActiveResultSets=False;Encrypt=True;TrustServerCertificate=False;Connection Timeout=30;"; 

它沒有連接到數據庫,我得到這個消息:

Server Error in '/' Application.

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)

我可以在VS.查詢數據庫

+0

你可以發佈這些防火牆設置的屏幕截圖嗎? – juunas

+1

這是Azure的一個很好的記錄(並且令人討厭,對我來說)安全特性。您需要進入Azure管理網頁,並允許您的特定IP地址訪問數據庫,或者允許範圍(或全部)IP地址訪問。 http://stackoverflow.com/questions/13406663/how-can-i-allow-unknown-users-to-access-my-sql-azure-db –

+0

Mike&Juunas,謝謝,我在我的防火牆設置中有這個:全部0.0.0.0 255.255.255.255。不能在這裏張貼一張照片。仍然得到相同的錯誤。謝謝。 – Peat

回答

0

I have created a database on Azure and connected to it and can see it connected in the SQL Object browser.

I had this in my firewall settings though: All 0.0.0.0 255.255.255.255.

看來你的所有IP地址,這應使您能夠從本地運行應用程序訪問SQL Azure數據庫提供訪問SQL Azure數據庫。請確保您是否在連接字符串中指定了正確的SQL服務器名稱「uvaluedb2」。你可以從Azure門戶get Connection string

此外,請嘗試創建新的SQL Azure數據庫並配置防火牆規則,然後從您的應用程序訪問它以檢查是否會出現相同的問題。