2010-12-21 31 views
1

我在本地連接Northwind.mdf但是當我上傳應用程序遠程服務器上,然後我得到以下錯誤:IIS:連接到數據庫.MDF - 網絡配置問題

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)

這些都是我試過幾個選項:

<connectionStrings> 
     <add name="ConnectionString" connectionString="Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\Northwind.mdf;Integrated Security=True;User Instance=True" providerName="System.Data.SqlClient"/> 
    </connectionStrings> 

上面的一個在當地工作。

<connectionStrings> 
      <add name="ConnectionString" connectionString="Data Source=.\SQLEXPRESS;AttachDbFilename=D:\ASP\TestSite\App_Data\Northwind.mdf; Integrated Security=True;Connect Timeout=30;User Instance=True;Trusted_Connection=Yes"/> 
     </connectionStrings> 

在服務器上安裝SQL Server 2005

感謝,
伊利亞·

+0

你的連接〜應變g表示** Express **版本,但您只提到「SQL Server 2005」 - 它是什麼?它是SQL Server 2005 ** Express **在您的遠程主機上,還是完整版本的SQL Server 2005? – 2010-12-21 15:54:49

回答

1

請執行以下步驟: 1:使用Sql server Management Studio將Northwind.mdf附加到您的服務器上的Sql Server 2005。 2:修改web.config中的connectionstring,使其指向服務器上的db。

How to detach/attach db.

+0

嗨,我也有同樣的問題。我已經在app_data文件夾中添加了visual studio中的mdf文件。我的連接字符串是_Data Source =。\ SQLEXPRESS; AttachDbFilename = | DataDirectory | \ Database.mdf;集成安全性= True;用戶實例= True_。我通過filezilla上傳我的項目。那麼是否有其他方法來解決問題 – 2013-09-01 04:01:27

1

幾件事情要檢查:

  1. 是數據庫文件確實在那個位置?
  2. 應用程序池是否具有對該目錄的讀/寫權限?
  3. SQL Express服務是否實際運行?
1

這裏有幾點需要檢查:

  • 如果要部署到一個共享的託管環境中的機會,主機將無法在網絡服務器上運行SQL Server。請他們確認並提供給您。

  • 您使用的連接字符串看起來很可疑。如果SQL Server已經安裝在服務器上,但作爲「默認」實例,則不需要連接字符串Data Source\SQLEXPRESS部分。只需使用.(local)即可。

  • 如果確實安裝了SQL Express並且它已安裝實例名稱SQLEXPRESS,請檢查站點標識是否具有有效的登錄名和數據庫的正確權限。此標識可以是工作進程帳戶(NETWORK SERVICE,ApplicationPoolIdentity,自定義帳戶)或站點的IIS匿名帳戶(如果啓用了ASP.NET模擬)。

我的最後一點是非常重要的:

  • AttachDbFilenameUser Instance=True專用於支持被稱爲 「User Instances」 概念的SQL Express。此功能是而不是適合專用或共享主機環境。

我的建議是

  • 搞清楚版本和版本的SQL Server可供您使用
  • 找出其託管(本地服務器上,或另一臺機器)
  • 看看它的配置爲「默認」實例或命名實例