部署后无法访问远程数据库

时间:2013-01-30 12:43:03

标签: asp.net sql-server-2008 iis web-deployment

我意识到那里有很多“解决方案”,但没有一个解决了我的问题。

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

我的数据库在我的开发服务器上连接,但不在产品上。我的开发机器是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,但仍然得到相同的消息,堆栈略有不同。

开始撕掉我的头发。救命啊!

3 个答案:

答案 0 :(得分:2)

让我坚持。请尝试以这种方式DROP和CREATE登录和db-user:

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

-- 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

答案 1 :(得分:0)

最明显的解释是最简单的:您在该数据库服务器上拥有该帐户的错误密码。我假设你已经验证了

  1. 该帐户存在于SQL 2008服务器上;
  2. 您可以使用您正在使用的密码登录吗?
  3. 另外,为什么在生产机器上提到“localhost”?您的数据库与Web服务器在同一台计算机上吗? (不一定是个好主意。)无论哪种方式,您都需要使用数据库服务器名称,而不是网络上的计算机名称。

答案 2 :(得分:0)

确保PingtreeUser具有Pingtree数据库的必要权限。

  1. 在MS SQL Server Management Studio中,使用sa帐户或Windows身份验证
  2. 登录
  3. 展开.\SQLEXPRESS > Security > Logins文件夹
  4. 双击PingtreeUser
  5. 确保Default databasePingtree
  6. 点击左侧的User Mapping
  7. 确保选中Pingtree数据库
  8. 点击底部,查看db_owner
  9. 点击Ok
  10. 这应该为PingtreeUser提供访问Pingtree数据库的必要权限。