2016-11-09 63 views
0

創建了一個帶有一個aspx頁面和管理器類的示例應用程序。從vs studio運行它時,我的輸出正常。 當我發佈它並將這些文件放入interpub - > wwwroot - > New Folder並打開IIS管理器時,將新建文件夾轉換爲應用程序並運行它。它的失敗,顯示無法連接到數據庫並顯示計算機名稱的錯誤。在本地託管之後,SQL窗口身份驗證無法正常工作

我認爲託管應用程序試圖連接數據庫使用計算機名稱而不是用戶名。如何解決這個問題? 我在下面添加我的web.config文件和經理類文件。

的web.config

<configuration> 
<system.web> 
    <compilation debug="true" targetFramework="4.5" /> 
    <httpRuntime targetFramework="4.5" /> 
</system.web> 
<connectionStrings> 
<add name="TestConnection" connectionString="data source=localhost\alex;initial catalog=Alex_Test; integrated security=SSPI; persist security info=False; Trusted_Connection=Yes"/> 
</connectionStrings> 
</configuration> 

Manager.cs

string Connection = ConfigurationManager.ConnectionStrings["TestConnection"].ToString(); 
SqlConnection conn = null; 
SqlCommand command = new SqlCommand();   
SqlDataAdapter sqlDataAdapter = null; 
conn.Open(); 
command.Connection = conn; 
sqlDataAdapter = new SqlDataAdapter("SELECT FirstName,LastName FROM Employees ", conn); 
dataSet = new DataSet(); 
sqlDataAdapter.Fill(dataSet, "Employees"); 

回答

1

批給/給你的IIS用戶對工人訪問數據庫或者你可以改變你的web.config的ConnectionString使用顯式用戶名和密碼。

Server=serverAddr;Database=dbName;User Id=Username; 
Password=Password; 
+0

感謝Landern。 您可以解釋如何授予/給予IIS用戶工作人員訪問數據庫的權限 –

+0

MSDN有一個鏈接,您的milage可能會有所不同,具體取決於您的設置以及您是否將MSSQL與SQL Management Studio配合使用。 https://technet.microsoft.com/en-us/library/ms172405(v=sql.105).aspx – Landern

0

我通過添加下面的代碼修改了本地部署代碼的web.config。

<authorization> 
<deny users="?"/> 
</authorization> 
<identity impersonate="true" userName="userName" password="password" /> 
</system.web> 
<system.webServer> 
<validation validateIntegratedModeConfiguration="false" /> 
</system.webServer> 

和更改IIS身份驗證設置 - >匿名身份驗證禁用

相關問題