2012-01-08 64 views
2

我是一個Asp.Net初學者,我正嘗試創建一個基於Web的應用程序。當我將ASP.Net與SQL Server 2005連接時,它會在執行應用程序時顯示以下錯誤。無法在SQL Server 2005與asp.Net之間建立連接

An error has occurred while establishing a connection to the server. When connecting to SQL Server 2005, this failure may be caused by the fact that under the default settings SQL Server does not allow remote connections. (provider: Named Pipes Provider, error: 40 - Could not open a connection to SQL Server)

儘管我嘗試了足夠的嘗試,但無法獲得解決方案,現在我需要您的幫助來解決這個問題。

在此先感謝。

更新:這裏是我的連接字符串從web.config

<add name="cn" 
    connectionString="DataSource=PT-7DBE27DA8;InitialCatalog=Pages;IntegratedSecurity=True" 
    providerName="System.Data.SqlClient"/> 
+3

發佈您的連接字符串將幫助我們來幫助你。 – TheGeekYouNeed 2012-01-08 12:28:49

+0

@TheGeekYouNeed true,Anshdeep - 只要確保從該字符串中刪除任何密碼或敏感的東西。我們只需要看看你如何嘗試連接。 – 2012-01-08 12:33:26

+1

檢查您的連接字符串與http://connectionstrings.com上的示例 – Oded 2012-01-08 12:41:39

回答

0

請在Visual Studio Server Explorer的連接,然後單擊測試連接按鈕,以確保一切正常。

然後點擊數據庫並選擇屬性。 在屬性窗口中,您可以找到正確的ConnectionString,您可以將其複製到代碼中。

+0

感謝您的回覆。但我仍然執行時發生同樣的錯誤。 – 2012-01-08 12:43:33

0

有這麼多的理由:

  • 與SQL Server的主機不可用,現在(ping通)
  • 你忘了通知連接中的字符串實例(檢查)
  • SQL服務器(檢查它,運行它)
  • 你使用tcpip或netpipes傳輸,它可以通過服務器配置關閉(檢查它)
  • 在你和sql server之間可能存在一個防火牆(telnet它在1433端口,UF使用TCPIP,否則 - 檢查),你的情況 - 命名管道 - 檢查端口445
  • 和還有更多這樣的(google一下8-)
0

Here你可以找到有用的信息,幫助您解決問題。

0

如果您檢查connectionstrings.com,您會發現連接字符串錯誤。

您需要使用兩種:

Data Source=PT-7DBE27DA8;Initial Catalog=Pages;Integrated Security=True 

(注意空間DataSource之間和Initial之間CatalogIntegrated之間Security

或:

server=PT-7DBE27DA8;database=Pages;Integrated Security=SSPI 

這第二個是我的首選方案 - server似乎比data source這麼清楚得多(這同樣適用於databaseinitial catalog