1

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

我最近创建了一个网站,并在生产机器上使用 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 从等式中删除,但仍然得到相同的消息,但堆栈略有不同。

开始扯我的头发。帮助!

4

3 回答 3

2

让我坚持。请尝试以这种方式 DROP 和 CREATE login 和 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
于 2013-01-30T16:51:09.337 回答
0

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

  1. 该帐户存在于 SQL 2008 服务器上;
  2. 您可以使用您使用的密码登录吗?

另外,你为什么在生产机器上指的是“localhost”?您的数据库与您的 Web 服务器在同一台机器上吗?(不一定是个好主意。)无论哪种方式,您都需要使用数据库服务器名称,而不是网络上的机器名称。

于 2013-01-30T13:25:11.447 回答
0

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

  1. 在 MS SQL Server Management Studio 中,使用sa帐户或通过 Windows 身份验证登录
  2. 展开.\SQLEXPRESS > Security > Logins文件夹
  3. 双击PingtreeUser
  4. 确保这Default databasePingtree
  5. 点击User Mapping左侧
  6. 确保Pingtree检查数据库
  7. 在底部,检查db_owner
  8. 点击Ok

这应该提供PingtreeUser访问Pingtree数据库的必要权限。

于 2013-01-30T15:27:36.687 回答