2011-03-25 121 views
3

我的全新Server 2008 R2 Server不接受來自我的MVC3應用程序的連接。無法從MVC應用程序連接到SQL Server Express 2008

我一直試圖讓這工作3天。它只是不會通過瀏覽器連接。但是,我可以通過SQL Server Mgmt Studio以用戶憑據登錄,也可以以管理員身份登錄。

我也做了以下內容:

  • 設置遠程連接被接受
  • 啓用命名管道/ TCP /共享存儲器
  • 禁用(即使IIS和SQLEXPRESS在同一機器上運行)用於TCP配置的動態端口(使其變爲空白)
  • TCP配置的指定端口
  • 禁用的Windows防火牆

我意識到這是一個通用的錯誤,但它只是不會連接。

連接字符串:

add name="Main.ConnectionString" 
    connectionString="Data Source=.\sqlexpress;Initial Catalog=BJ;User Id=Jameson;Password=pass!;" 

我得到以下錯誤(YSOD):

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)

[SqlException (0x80131904): 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)]

如何這個問題能解決?

+0

什麼是您的實例的名稱* SQLEXPRESS *?你的連接字符串是什麼樣的?(當然祕密位已更改) – Tahbaza 2011-03-25 23:54:27

回答

2

幾troublehshooting東西的問題,我會檢查:

  • 是你的代碼明確使用Main.ConnectionString?仔細檢查 - 我已經看到LINQ To SQL在.dbml中有一個硬編碼連接字符串的情況。我意識到你沒有提到LINQ To SQL,但是這也可以用於EF。

  • 在您的代碼中查找硬編碼連接字符串的任何殘餘。

  • 重新部署將項目與新的構建

  • 沒有你的開發工作站相同的連接字符串連接OK?

+0

我在應用程序中使用了一個硬編碼的查詢字符串,並且以某種方式調用了該字符串。謝謝你的幫助。 – 2011-03-26 17:56:29

+1

@Dr .:沒問題,很高興幫忙!請記住用綠色選中標記「接受」最佳答案。它是StackOverflow聲譽系統的一部分。 – 2011-03-26 19:06:25

2

如果您使用的是SQL身份驗證的連接字符串應該是這樣的:

Data Source=myServerAddressIP\SQLEXPRESS;Initial Catalog=myDataBase;User Id=myUsername;Password=myPassword; 

,如果你正在使用Windows身份驗證:

Data Source=myServerAddressIP\SQLEXPRESS;Initial Catalog=myDataBase;Integrated Security=SSPI; 

還要確保防火牆不會阻止連接。

欲瞭解更多信息結賬following site。如果你仍然有麻煩配置您的SQL Server不要猶豫,問你對https://serverfault.com/