本文介绍了部署后无法访问远程数据库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我意识到那里有很多解决方案",但是没有一个解决了我的问题.

I realise there's a lot of 'solutions' out there but none that have resolved my issue.

我最近创建了一个网站,并正在生产计算机上使用iis7.5/sql server 2008.

I have recently created a website and am using iis7.5/sql server 2008 on the production machine.

我的数据库连接到我的开发服务器上,但没有连接到productin机器上.我的开发机是sql express 2008.

My database connects on my dev server but does not on the productin machine. My dev machine is sql express 2008.

这里是联系:

<add name="PingtreeEntities"
  providerName="System.Data.EntityClient"
  connectionString="metadata=
  res://*/;
  provider=System.Data.SqlClient;
  provider connection string=&quot;
  Data Source=localhost;
  Initial Catalog=Pingtree;
  Integrated Security=False;
  User Id=PingtreeUser;
  Password=*********;
  MultipleActiveResultSets=True&quot;" />

这是我收到的消息:

[SqlException (0x80131904): Cannot open database "Pingtree" requested by the login. The login failed.
Login failed for user 'PingtreeUser'.]
   System.Data.SqlClient.SqlInternalConnection.OnError(SqlException exception, Boolean breakConnection) +6333056
   System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning() +412
   System.Data.SqlClient.TdsParser.Run(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj) +1363
   System.Data.SqlClient.SqlInternalConnectionTds.CompleteLogin(Boolean enlistOK) +53
   System.Data.SqlClient.SqlInternalConnectionTds.LoginNoFailover(ServerInfo serverInfo, String newPassword, Boolean redirectedUserInstance, SqlConnection owningObject, SqlConnectionString connectionOptions, TimeoutTimer timeout) +6348014
   System.Data.SqlClient.SqlInternalConnectionTds.OpenLoginEnlist(SqlConnection owningObject, TimeoutTimer timeout, SqlConnectionString connectionOptions, String newPassword, Boolean redirectedUserInstance) +6347929
   System.Data.SqlClient.SqlInternalConnectionTds..ctor(DbConnectionPoolIdentity identity, SqlConnectionString connectionOptions, Object providerInfo, String newPassword, SqlConnection owningObject, Boolean redirectedUserInstance) +352
   System.Data.SqlClient.SqlConnectionFactory.CreateConnection(DbConnectionOptions options, Object poolGroupProviderInfo, DbConnectionPool pool, DbConnection owningConnection) +831
   System.Data.ProviderBase.DbConnectionFactory.CreatePooledConnection(DbConnection owningConnection, DbConnectionPool pool, DbConnectionOptions options) +49
   System.Data.ProviderBase.DbConnectionPool.CreateObject(DbConnection owningObject) +6349734
   System.Data.ProviderBase.DbConnectionPool.UserCreateRequest(DbConnection owningObject) +78
   System.Data.ProviderBase.DbConnectionPool.GetConnection(DbConnection owningObject) +1938
   System.Data.ProviderBase.DbConnectionFactory.GetConnection(DbConnection owningConnection) +89
   System.Data.ProviderBase.DbConnectionClosed.OpenConnection(DbConnection outerConnection, DbConnectionFactory connectionFactory) +6352606
   System.Data.SqlClient.SqlConnection.Open() +300
   System.Data.EntityClient.EntityConnection.OpenStoreConnectionIf(Boolean openCondition, DbConnection storeConnectionToOpen, DbConnection originalConnection, String exceptionCode, String attemptedOperation, Boolean& closeStoreConnectionOnFailure) +67

[EntityException: The underlying provider failed on Open.]
   System.Data.EntityClient.EntityConnection.OpenStoreConnectionIf(Boolean openCondition, DbConnection storeConnectionToOpen, DbConnection originalConnection, String exceptionCode, String attemptedOperation, Boolean& closeStoreConnectionOnFailure) +11079326
   System.Data.EntityClient.EntityConnection.Open() +142
   System.Data.Objects.ObjectContext.EnsureConnection() +97
   System.Data.Objects.ObjectQuery`1.GetResults(Nullable`1 forMergeOption) +66
   System.Data.Objects.ObjectQuery`1.System.Collections.Generic.IEnumerable<T>.GetEnumerator() +47
   System.Linq.Enumerable.SingleOrDefault(IEnumerable`1 source) +271
   System.Linq.Queryable.SingleOrDefault(IQueryable`1 source) +383
   Pingtree.BLL.Data.Applicants.Find(Applicant applicant) in C:\Documents and Settings\John\My Documents\Visual Studio 2010\Projects\Pingtree\BLL\Data\Applicants.cs:32
   Pingtree.BLL.Data.Applications.Test(Applicant applicant, Application application, AcceptedApplication acceptedApplication, ContactPermission contactPermission) in C:\Documents and Settings\John\My Documents\Visual Studio 2010\Projects\Pingtree\BLL\Data\Applications.cs:24
   Pingtree.Public.Test.Add_Click(Object sender, EventArgs e) in C:\Documents and Settings\John\my documents\visual studio 2010\Projects\Pingtree\Pingtree\Public\Test.aspx.cs:107
   System.Web.UI.WebControls.Button.RaisePostBackEvent(String eventArgument) +154
   System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +3707

我曾尝试通过使用直连接从等式中删除EF,但仍然得到相同的消息,但堆栈稍有不同.

I have tried removing EF out of the equation by using a straight connection but still get the same message with a slightly different stack.

开始把我的头发扯掉.救命!

Starting to tear my hair out. Help!

推荐答案

让我坚持.请尝试以这种方式删除和创建登录名和db-user:

Let me insist. Please try to DROP and CREATE both login and db-user in this way:

(请注意,您必须将密码更改为您使用的密码)

-- Drop & recreate login
USE [master]
GO
IF EXISTS(SELECT * FROM sys.syslogins WHERE name = N'PingtreeUser')
    DROP LOGIN [PingtreeUser];
GO
CREATE LOGIN [PingtreeUser]
    WITH
        PASSWORD=N'password',
        DEFAULT_DATABASE=[Pingtree],
        CHECK_EXPIRATION=OFF, CHECK_POLICY=OFF
GO

-- Drop & recreate db-user
USE [Pingtree]
GO
IF  EXISTS (SELECT * FROM sys.database_principals WHERE name = N'PingtreeUser')
    DROP USER [PingtreeUser];
GO
CREATE USER [PingtreeUser] FOR LOGIN [PingtreeUser]
GO
EXEC sp_addrolemember N'db_owner', N'PingtreeUser'
GO

这篇关于部署后无法访问远程数据库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-28 19:05