【发布时间】:2014-04-30 08:18:38
【问题描述】:
我有一个 ASP.NET 项目,它使用存储在 App_Data 文件夹中的本地 .mdf 数据库。我通常将网站本地发布到我的桌面,然后获取所有文件并将它们上传到 asp.net 服务器。
上传成功后,由于某些原因无法访问数据库。
我已经在我的 web.config 中包含了数据库的连接字符串
<connectionStrings>
<clear />
<add name="LocalSqlServer" connectionString="Data Source=(LocalDB)\v11.0;AttachDBFilename=|DataDirectory|database.mdf;database=database;Integrated Security=True;User Instance=False;Context Connection=False;" providerName="System.Data.SqlClient"/>
</connectionStrings>
我没有看到一些在线解决方案声明将 LocalDB)\v11.0 更改为 .\SQLEXPRESS;在连接字符串中,但这不起作用。
请告知如何正确上传项目中的数据库并设置对它的正确访问权限。
当我尝试打开数据库连接时,我收到以下错误消息
System.Security.SecurityException:请求失败。在 System.Security.CodeAccessSecurityEngine.Check(Object demand, StackCrawlMark& stackMark, Boolean isPermSet) 在 System.Security.CodeAccessSecurityEngine.Check(PermissionSet permSet, StackCrawlMark& stackMark) 在 System.Security.PermissionSet.Demand() 在 System.Data.LocalDBAPI.DemandLocalDBPermissions() 在 System.Data.LocalDBAPI.CreateLocalDBInstance(String 实例) 在 System.Data.SqlClient.TdsParser.Connect(ServerInfo serverInfo, SqlInternalConnectionTds connHandler, Boolean ignoreSniOpenTimeout, Int64 timerExpire, Boolean encrypt, Boolean trustServerCert,在 System.Data.SqlClient.SqlInternalConnectionTds.AttemptOneLogin (ServerInfo serverInfo, String newPassword, SecureString newSecurePassword, Boolean ignoreSniOpenTimeout, TimeoutTimer timeout, Boolean withFailover) 在 System.Data.SqlClient.SqlInternalConnectionTds.LoginNoFailover(ServerInfo serverInfo, String newPassword、SecureString newSecurePassword、Boolean redirectedUserInstance、SqlConnectionString connectionOptions、SqlCredential credential、TimeoutTimer timeout)在 System.Data.SqlClient.SqlInternalConnectionTds.OpenLoginEnlist(TimeoutTimer 超时、SqlConnectionString connectionOptions、SqlCredential credential、String newPa ssword, SecureString newSecurePassword, Boolean redirectedUserInstance) 在 System.Data.SqlClient.SqlInternalConnectionTds..ctor(DbConnectionPoolIdentity identity, SqlConnectionString connectionOptions, SqlCredential credential, Object providerInfo, String newPassword, SecureString newSecurePassword, Boolean redirectedUserInstance, SqlConnectionString userConnectionOptions) 在 System.Data.SqlClient System.Data.ProviderBase.DbConnectionFactory.CreatePooledConnection(DbConnectionPool pool, DbConnectionOptions options, DbConnectionPoolKey poolKey, DbConnectionOptions userOptions) at System.Data.SqlConnectionFactory.CreateConnection(DbConnectionOptions options, DbConnectionPoolKey poolKey, Object poolGroupProviderInfo, DbConnectionPool pool, DbConnection owningConnection, DbConnectionOptions userOptions) .ProviderBase.DbConnectionPool.CreateObject(DbConnectionOptions userOptions) 在 System.Data.ProviderBase.DbConnectionPool.UserCreateRequest(DbConnectionOptions userOptions) 在 System.Data System.Data.ProviderBase.DbConnectionPool.TryGetConnection(DbConnection owningObject,TaskCompletionSource
1 retry, DbConnectionOptions userOptions, DbConnectionInternal& connection) at System.Data.ProviderBase.DbConnectionFactory.TryGetConnection(DbConnection owningConnection, TaskCompletionSource1 重试,DbConnectionOptions userOptions,DbConnectionInternal connection) at System.Data.ProviderBase.DbConnectionClosed.TryOpenConnection(DbConnection outerConnection, DbConnectionFactory connectionFactory, TaskCompletionSource1 retry, DbConnectionOptions userOptions) at System.Data.SqlClient.SqlConnection.TryOpen(TaskCompletionSource1 retry) at System.Data.SqlClient.SqlConnection.Open() at Database.establishConnection() 失败的操作是: Demand 第一个失败的权限类型是:System.Security.PermissionSet 失败的程序集的区域是:MyComputer
【问题讨论】:
-
“无法访问数据库”是什么意思?有错误信息吗?
-
错误信息如上。
-
我知道使用 SQL Server 您需要授予对 ASPNET 用户帐户的访问权限。你能用 Access 做同样的事情吗?我对访问不熟悉,但是一旦部署您的 Windows 帐户就不再与集成安全性一起使用。它需要是 ASPNET 用户帐户。
-
嗨,马特,不明白你在说什么!
-
您在连接字符串中设置了
Integrated Security=True,这意味着您的Web 应用程序需要在可以访问数据库的同一帐户下运行。如果这是共享主机,则可能不是这种情况,因为 Web 服务器不会使用您的帐户凭据运行。您需要调查您的主机提供的数据库选项,并利用他们的产品之一。
标签: c# asp.net database visual-studio-2010