2013-03-02 57 views
1

我有2個相同的連接字符串。一個是ASP.NET會員等,另一個是其他的。爲什麼只有其中一個連接字符串在它們實際上相同時才起作用?

我可以登錄到我的應用程序,所以下面的連接字符串顯然起作用。

<add name="ApplicationServices" connectionString="Data Source=SBS;Initial Catalog=CustomerIntranet;Integrated Security=True;" 
     providerName="System.Data.SqlClient" /> 

當我嘗試訪問安全網頁(基於角色的訪問),我得到的可怕:

System.Data.SqlClient.SqlException: 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) 

下面是其他連接字符串:

<add name="CustomerIntranetConnectionString" connectionString="Data Source=SBS;Initial Catalog=CustomerIntranet;Integrated Security=True;" 
    providerName="System.Data.SqlClient" /> 
  • 我通過遠程桌面連接連接到服務器。
  • 我通過一個瀏覽器,服務器
  • SQL服務器(SQLSERVER 2005)上運行的應用程序配置了遠程訪問反正
  • 我可以登錄
  • ASP.NET成員和其他數據庫的東西全部位於同一DB
  • 將應用程序部署在IIS 6.0
  • 應用程序運行在我的機器罰款(IIS 7.0)

如果任何人都可以她d在這個問題上有一些亮點,那將是非常棒的。我玩過連接字符串,但沒有成功。

只是爲了重申一下,我可以登錄,所以我明顯建立了與數據庫的連接。一旦我打到安全頁面,我就會收到錯誤信息。

謝謝。

PS這裏是堆棧

[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)] 
    System.Data.SqlClient.SqlInternalConnection.OnError(SqlException exception, Boolean breakConnection) +5009598 
    System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning() +234 
    System.Data.SqlClient.TdsParser.Connect(ServerInfo serverInfo, SqlInternalConnectionTds connHandler, Boolean ignoreSniOpenTimeout, Int64 timerExpire, Boolean encrypt, Boolean trustServerCert, Boolean integratedSecurity) +341 
    System.Data.SqlClient.SqlInternalConnectionTds.AttemptOneLogin(ServerInfo serverInfo, String newPassword, Boolean ignoreSniOpenTimeout, TimeoutTimer timeout, SqlConnection owningObject) +129 
    System.Data.SqlClient.SqlInternalConnectionTds.LoginNoFailover(ServerInfo serverInfo, String newPassword, Boolean redirectedUserInstance, SqlConnection owningObject, SqlConnectionString connectionOptions, TimeoutTimer timeout) +270 
    System.Data.SqlClient.SqlInternalConnectionTds.OpenLoginEnlist(SqlConnection owningObject, TimeoutTimer timeout, SqlConnectionString connectionOptions, String newPassword, Boolean redirectedUserInstance) +195 
    System.Data.SqlClient.SqlInternalConnectionTds..ctor(DbConnectionPoolIdentity identity, SqlConnectionString connectionOptions, Object providerInfo, String newPassword, SqlConnection owningObject, Boolean redirectedUserInstance) +232 
    System.Data.SqlClient.SqlConnectionFactory.CreateConnection(DbConnectionOptions options, Object poolGroupProviderInfo, DbConnectionPool pool, DbConnection owningConnection) +185 
    System.Data.ProviderBase.DbConnectionFactory.CreatePooledConnection(DbConnection owningConnection, DbConnectionPool pool, DbConnectionOptions options) +33 
    System.Data.ProviderBase.DbConnectionPool.CreateObject(DbConnection owningObject) +524 
    System.Data.ProviderBase.DbConnectionPool.UserCreateRequest(DbConnection owningObject) +66 
    System.Data.ProviderBase.DbConnectionPool.GetConnection(DbConnection owningObject) +479 
    System.Data.ProviderBase.DbConnectionFactory.GetConnection(DbConnection owningConnection) +108 
    System.Data.ProviderBase.DbConnectionClosed.OpenConnection(DbConnection outerConnection, DbConnectionFactory connectionFactory) +126 
    System.Data.SqlClient.SqlConnection.Open() +125 
    System.Data.Common.DbDataAdapter.FillInternal(DataSet dataset, DataTable[] datatables, Int32 startRecord, Int32 maxRecords, String srcTable, IDbCommand command, CommandBehavior behavior) +123 
    System.Data.Common.DbDataAdapter.Fill(DataTable[] dataTables, Int32 startRecord, Int32 maxRecords, IDbCommand command, CommandBehavior behavior) +166 
    System.Data.Common.DbDataAdapter.Fill(DataTable dataTable) +115 
    DataAccess.IntranetTableAdapters.employeeTableAdapter.GetEmployeeByUserID(Nullable`1 id) +377 
    BusinessClasses.GlobalOperations.getEmployeeByUserID(Guid id) +96 
    Customer.EmployeeTimesheet.prepareComponents() +327 
    Customer.EmployeeTimesheet.Page_Load(Object sender, EventArgs e) +179 
    System.Web.Util.CalliHelper.EventArgFunctionCaller(IntPtr fp, Object o, Object t, EventArgs e) +14 
    System.Web.Util.CalliEventHandlerDelegateProxy.Callback(Object sender, EventArgs e) +35 
    System.Web.UI.Control.OnLoad(EventArgs e) +91 
    System.Web.UI.Control.LoadRecursive() +74 
    System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +2207 

以下是完整的配置文件:

<?xml version="1.0"?> 

<configuration> 
    <connectionStrings> 
    <add name="ApplicationServices" connectionString="Data Source=SBS;Initial Catalog=CustomerIntranet;Integrated Security=True;" 
     providerName="System.Data.SqlClient" /> 
    <add name="IntranetConnectionString" connectionString="Data Source=SBS;Initial Catalog=CustomerIntranet;Integrated Security=True;" 
     providerName="System.Data.SqlClient" /> 
    </connectionStrings> 

    <system.web> 
    <compilation debug="true" targetFramework="4.0" /> 
    <httpRuntime maxRequestLength="8192" executionTimeout="360"/> 
    <authentication mode="Forms"> 
     <forms loginUrl="~/Account/Login.aspx" timeout="2880" /> 
    </authentication> 

    <membership> 
     <providers> 
     <clear/> 
     <add name="AspNetSqlMembershipProvider" type="System.Web.Security.SqlMembershipProvider" connectionStringName="ApplicationServices" 
      enablePasswordRetrieval="false" enablePasswordReset="true" requiresQuestionAndAnswer="false" requiresUniqueEmail="false" 
      maxInvalidPasswordAttempts="5" minRequiredPasswordLength="6" minRequiredNonalphanumericCharacters="0" passwordAttemptWindow="10" 
      applicationName="/" /> 
     </providers> 
    </membership> 

    <profile> 
     <providers> 
     <clear/> 
     <add name="AspNetSqlProfileProvider" type="System.Web.Profile.SqlProfileProvider" connectionStringName="ApplicationServices" applicationName="/"/> 
     </providers> 
    </profile> 

    <roleManager enabled="true" defaultProvider="MyRoleProvider"> 
     <providers> 
     <clear/> 
     <add name="MyRoleProvider" type="BusinessClasses.MyRoleProvider, BusinessClasses" /> 
     </providers> 
    </roleManager> 

    </system.web> 

    <system.webServer> 
    <modules runAllManagedModulesForAllRequests="true"/> 
    </system.webServer> 
</configuration> 
+0

如果您使用相同的初始目錄 - 爲什麼不使用相同的連接一切?試試看看MARS是否有幫助: OakNinja 2013-03-02 10:07:38

+0

感謝您的輸入。我不是100%確定,但我認爲ApplicationServices的東西是ASP.NET成員資格所必需的,因此它有自己的標籤。我嘗試了你的建議,但它沒有改變任何東西。 – spryce 2013-03-02 10:17:09

回答

0

我發現問題出在這個問題上。首先讓我添加一些與這個問題有關的更多信息。

我正在使用具有典型DataAccess,DataClasses(類型化數據集,xsd文件),業務和表示層的n層體系結構。

解決方案搜索範圍爲connectionString會顯示多個未被web.config覆蓋的硬編碼連接字符串(由VS提供)。這些顯然是在設置DataSet設計器時創建的。

部署應用程序時,web.config connectionStrings反映生產服務器,但硬編碼字符串仍然指向我的開發服務器。

我有限的理解是,web.config應該覆蓋應用程序中其他位置定義的任何其他連接字符串,如果它們具有相同的名稱。看起來情況並非如此。有人比我更聰明,可以詳細闡述一下。

簡而言之,如果您像我一樣有任何bizare問題,請對任何其他連接字符串進行解決方案廣泛搜索。它們可能在您不知情的情況下存在,並可能導致衝突。

2

此連接字符串控制實際上傳遞給系統

Data Source=SBS;Initial Catalog=CustomerIntranet;Integrated Security=True;

通過說控制,我的意思是系統和數據庫一起檢查他是否允許連接到數據庫。所以這就是一個案件而不是另一個案件的原因。

我建議,首先在Data Source=localhost上使用本地主機,除非你連接到另一臺計算機,那麼請確保你的服務器上的host文件正確配置了計算機的名稱,或者直接使用IP。

其次打開數據庫管理並確保該目錄存在,並且嘗試連接的池有權讀取該目錄。此外,數據庫的文件必須具有池的權限。

該池正在用戶帳戶或系統帳戶下運行。該帳戶必須有權讀取/寫入該數據庫,包括數據庫的文件以及數據庫的首選項。此外,該用戶必須位於數據庫的最大列表中。

+0

應用程序池標識是Network Service。 – spryce 2013-03-03 04:00:21

+0

對不起。應用程序池標識是網絡服務。我的SQL Server具有NT AUTHORITY \ NETWORK SERVICE的登錄名,而數據庫具有用戶NT AUTHORITY \ NETWORK SERVICE。該用戶被授予dbo.owner權限。我可以使用Data Source = localhost或SBS或127.0.0.1登錄到Web應用程序。我不理解你的評論「系統和數據庫一起檢查他是否允許連接到數據庫,所以這就是一個案件而不是另一個案件的原因。」這並沒有真正向我解釋爲什麼它適用於一個而不是另一個。你能否詳細說明一下。謝謝 – spryce 2013-03-03 04:07:49

+0

@spryce系統的意思是你在數據庫文件上設置的權限。這些文件必須允許池的用戶能夠讀寫。現在,在修復數據庫之後,還允許相同的用戶擁有讀寫權限。如果數據庫使用網絡服務,請再次檢查網絡服務是否運行該池,並且該文件具有網絡服務的讀/寫權限。 – Aristos 2013-03-03 09:01:57

相關問題