web.config中的double connectionstring

时间:2016-03-22 09:50:11

标签: database web-config

我有两个连接到两个不同的数据库,但是在同一个数据服务上。第二个连接字符串用于加载产品。所以我可以运行本地站点:http://localhost/home-1。但是,如果我想查看产品的详细信息,例如:http://localhost/catalog?GroupID=00015我收到此错误:

System.Data.EntityException: The underlying provider failed on Open. ---> System.Data.SqlClient.SqlException: Login failed for user 'VERPLOEGEN\Niels'.
   at System.Data.SqlClient.SqlInternalConnectionTds..ctor(DbConnectionPoolIdentity identity, SqlConnectionString connectionOptions, SqlCredential credential, Object providerInfo, String newPassword, SecureString newSecurePassword, Boolean redirectedUserInstance, SqlConnectionString userConnectionOptions, SessionData reconnectSessionData, DbConnectionPool pool, String accessToken, Boolean applyTransientFaultHandling)
   at System.Data.SqlClient.SqlConnectionFactory.CreateConnection(DbConnectionOptions options, DbConnectionPoolKey poolKey, Object poolGroupProviderInfo, DbConnectionPool pool, DbConnection owningConnection, DbConnectionOptions userOptions)
   at System.Data.ProviderBase.DbConnectionFactory.CreatePooledConnection(DbConnectionPool pool, DbConnection owningObject, DbConnectionOptions options, DbConnectionPoolKey poolKey, DbConnectionOptions userOptions)
   at System.Data.ProviderBase.DbConnectionPool.CreateObject(DbConnection owningObject, DbConnectionOptions userOptions, DbConnectionInternal oldConnection)
   at System.Data.ProviderBase.DbConnectionPool.UserCreateRequest(DbConnection owningObject, DbConnectionOptions userOptions, DbConnectionInternal oldConnection)
   at System.Data.ProviderBase.DbConnectionPool.TryGetConnection(DbConnection owningObject, UInt32 waitForMultipleObjectsTimeout, Boolean allowCreate, Boolean onlyOneCheckConnection, DbConnectionOptions userOptions, DbConnectionInternal& connection)
   at System.Data.ProviderBase.DbConnectionPool.TryGetConnection(DbConnection owningObject, TaskCompletionSource`1 retry, DbConnectionOptions userOptions, DbConnectionInternal& connection)
   at System.Data.ProviderBase.DbConnectionFactory.TryGetConnection(DbConnection owningConnection, TaskCompletionSource`1 retry, DbConnectionOptions userOptions, DbConnectionInternal oldConnection, DbConnectionInternal& connection)
   at System.Data.ProviderBase.DbConnectionInternal.TryOpenConnectionInternal(DbConnection outerConnection, DbConnectionFactory connectionFactory, TaskCompletionSource`1 retry, DbConnectionOptions userOptions)
   at System.Data.SqlClient.SqlConnection.TryOpenInner(TaskCompletionSource`1 retry)
   at System.Data.SqlClient.SqlConnection.TryOpen(TaskCompletionSource`1 retry)
   at System.Data.SqlClient.SqlConnection.Open()
   at System.Data.EntityClient.EntityConnection.OpenStoreConnectionIf(Boolean openCondition, DbConnection storeConnectionToOpen, DbConnection originalConnection, String exceptionCode, String attemptedOperation, Boolean& closeStoreConnectionOnFailure)
   --- End of inner exception stack trace ---
   at System.Data.EntityClient.EntityConnection.OpenStoreConnectionIf(Boolean openCondition, DbConnection storeConnectionToOpen, DbConnection originalConnection, String exceptionCode, String attemptedOperation, Boolean& closeStoreConnectionOnFailure)
   at System.Data.EntityClient.EntityConnection.Open()
   at System.Data.Objects.ObjectContext.EnsureConnection()
   at System.Data.Objects.ObjectQuery`1.GetResults(Nullable`1 forMergeOption)
   at System.Data.Objects.ObjectQuery`1.System.Collections.Generic.IEnumerable.GetEnumerator()
   at System.Linq.Enumerable.FirstOrDefault[TSource](IEnumerable`1 source)
   at bdProductListNotification.bdProductListSetL3Notification.OnNotify(String notification, NotificationArgs args)
   at Dynamicweb.Extensibility.NotificationManager.Notify(String notification, Object[] args)
   at Dynamicweb.eCommerce.Frontend.Frontend.ListProducts(ProductCollection products, String groupsIdent, Boolean hasBeenSorted)
   at Dynamicweb.eCommerce.Frontend.Frontend.List(String groups)
   at Dynamicweb.eCommerce.Frontend.Frontend.EcomRender()
   at Dynamicweb.eCommerce.Frontend.Frontend.GetContent()
   at Dynamicweb.Frontend.Content.GetModule(DataRow& ParagraphRow)

connectionstrrings看起来像这样:

<connectionStrings>
    <add name="DataAccess_DynamicWebEntities" connectionString="metadata=res://*/DataAccess_DynamicWeb.csdl|res://*/DataAccess_DynamicWeb.ssdl|res://*/DataAccess_DynamicWeb.msl;provider=System.Data.SqlClient;provider connection string=&quot;data source=DESKTOP-UON3ACI\SQLEXPRESS;initial catalog=Dynamicweb-Verploegen-Test_new;user id='VERPLOEGEN\Niels';password='';multipleactiveresultsets=True;application name=EntityFramework&quot;" providerName="System.Data.EntityClient" />
    <add name="NAV2DWservice.Properties.Settings.NAVconnectionString" connectionString="Data Source=DESKTOP-UON3ACI\SQLEXPRESS;Integrated Security=no;Initial catalog=Verploegen-Test;user=sa;password=8Bit235711" />
    <!-- <add connectionString="Data Source=DESKTOP-UON3ACI\SQLEXPRESS;Integrated Security=yes;Initial catalog=Verploegen-Test;user id=''" name="NAV2DWservice.Properties.Settings.NAVconnectionString" />-->
    <add name="DefaultConnection" providerName="System.Data.SqlClient" connectionString="Data Source=(LocalDb)\MSSQLLocalDB;Initial Catalog=aspnet-localhost-20160318120328;Integrated Security=SSPI;AttachDBFilename=|DataDirectory|\aspnet-localhost-20160318120328.mdf" />
  </connectionStrings>

谢谢

1 个答案:

答案 0 :(得分:0)

嗯,您需要在调用数据库查询时获取cs文件中的特定连接字符串值,因为您正在使用多个连接字符串。 这将帮助您从正确的数据库中获得所需的结果。

请参阅以下链接了解更多信息 http://www.codeproject.com/Questions/542852/howplustoplususeplusmultipleplusconnectionstringpl

相关问题