Web用户只能访问一个数据库

时间:2014-07-08 16:27:01

标签: sql-server iis-7.5

我在IIS 7.5中运行的网站很少,每个网站都使用每个配置文件中的connectionStrings部分映射到自己的相关数据库。字符串使用“Integrated Security = SSPI”,到目前为止一切正常,用户可以读取和写入各自的dbs。 IIS和SQL Server位于同一台计算机上,并且SQL设置为混合身份验证。

我想设置Integrated Security=false并将user=mySpecifDb;pwd=test123添加到字符串中,但它不起作用。该网站引发数据库连接错误。我使用SSMS创建了用户“mySpecifDb”,并遵循了目前为止的所有说明。我可以使用凭据“mySpecifDb”和“test123”登录SSMS,我可以读取和写入所选数据库,只能读取和写入。我无法使用这些凭据访问任何其他数据库,这就是我想要的。在IIS 7.5中,所有网站都使用DefaultAppPool。我不知道从这一点上去哪里。

编辑:这是具有真实凭据的真实连接字符串。如前所述,我可以使用它们登录SSMS,只读取/写入AutoParkDemo db。如果我只是将“true”更改为“SSPI”,那么一切正常。

 <connectionStrings>
    <clear />
   <add name="AutoPark" connectionString="Data Source=(LocalDb)\v11.0;Initial Catalog=AutoParkDemo;Integrated Security=false;user=apmDemo;pwd=*****" providerName="System.Data.SqlClient" />
  </connectionStrings>

编辑:

Server Error in '/Manager' Application.
Login failed for user 'apmDemo'.
Exception Details: System.Data.SqlClient.SqlException: Login failed for user 'apmDemo'.
Stack Trace: 

[SqlException (0x80131904): Login failed for user 'apmDemo'.]
   System.Data.ProviderBase.DbConnectionPool.TryGetConnection(DbConnection owningObject, UInt32 waitForMultipleObjectsTimeout, Boolean allowCreate, Boolean onlyOneCheckConnection, DbConnectionOptions userOptions, DbConnectionInternal& connection) +642
   System.Data.ProviderBase.DbConnectionPool.TryGetConnection(DbConnection owningObject, TaskCompletionSource`1 retry, DbConnectionOptions userOptions, DbConnectionInternal& connection) +116
   System.Data.ProviderBase.DbConnectionFactory.TryGetConnection(DbConnection owningConnection, TaskCompletionSource`1 retry, DbConnectionOptions userOptions, DbConnectionInternal oldConnection, DbConnectionInternal& connection) +1089
   System.Data.ProviderBase.DbConnectionInternal.TryOpenConnectionInternal(DbConnection outerConnection, DbConnectionFactory connectionFactory, TaskCompletionSource`1 retry, DbConnectionOptions userOptions) +6785863
   System.Data.SqlClient.SqlConnection.TryOpenInner(TaskCompletionSource`1 retry) +233
   System.Data.SqlClient.SqlConnection.TryOpen(TaskCompletionSource`1 retry) +278
   System.Data.SqlClient.SqlConnection.Open() +239
   System.Data.Entity.Infrastructure.Interception.InternalDispatcher`1.Dispatch(TTarget target, Action`2 operation, TInterceptionContext interceptionContext, Action`3 executing, Action`3 executed) +207
   System.Data.Entity.Infrastructure.Interception.DbConnectionDispatcher.Open(DbConnection connection, DbInterceptionContext interceptionContext) +438
   System.Data.Entity.SqlServer.<>c__DisplayClass1.<Execute>b__0() +15
   System.Data.Entity.SqlServer.DefaultSqlExecutionStrategy.Execute(Func`1 operation) +263
   System.Data.Entity.SqlServer.SqlProviderServices.UsingConnection(DbConnection sqlConnection, Action`1 act) +375
   System.Data.Entity.SqlServer.SqlProviderServices.UsingMasterConnection(DbConnection sqlConnection, Action`1 act) +749
   System.Data.Entity.SqlServer.SqlProviderServices.GetDbProviderManifestToken(DbConnection connection) +504
   System.Data.Entity.Core.Common.DbProviderServices.GetProviderManifestToken(DbConnection connection) +118

[ProviderIncompatibleException: The provider did not return a ProviderManifestToken string.]
   System.Data.Entity.Core.Common.DbProviderServices.GetProviderManifestToken(DbConnection connection) +459
   System.Data.Entity.Utilities.DbProviderServicesExtensions.GetProviderManifestTokenChecked(DbProviderServices providerServices, DbConnection connection) +51

[ProviderIncompatibleException: An error occurred accessing the database. This usually means that the connection to the database failed. Check that the connection string is correct and that the appropriate DbContext constructor is being used to specify it or find it in the application's config file. See http://go.microsoft.com/fwlink/?LinkId=386386 for information on DbContext and connections. See the inner exception for details of the failure.]
   System.Data.Entity.Utilities.DbProviderServicesExtensions.GetProviderManifestTokenChecked(DbProviderServices providerServices, DbConnection connection) +300
   System.Collections.Concurrent.ConcurrentDictionary`2.GetOrAdd(TKey key, Func`2 valueFactory) +83
   System.Data.Entity.Infrastructure.DefaultManifestTokenResolver.ResolveManifestToken(DbConnection connection) +327
   System.Data.Entity.DbModelBuilder.Build(DbConnection providerConnection) +118
   System.Data.Entity.Internal.LazyInternalContext.CreateModel(LazyInternalContext internalContext) +94
   System.Data.Entity.Internal.RetryLazy`2.GetValue(TInput input) +248
   System.Data.Entity.Internal.LazyInternalContext.InitializeContext() +618
   System.Data.Entity.Internal.InternalContext.CreateObjectContextForDdlOps() +23
   System.Data.Entity.Database.Exists() +40
   Microsoft.AspNet.Identity.EntityFramework.IdentityDbContext`1.IsIdentityV1Schema(DbContext db) +168
   Microsoft.AspNet.Identity.EntityFramework.IdentityDbContext`1..ctor(String nameOrConnectionString, Boolean throwIfV1Schema) +80
   AutoParkManager.Models.ApplicationDbContext..ctor() in c:\AppVS2013\AutoPark\AutoParkManager\Models\IdentityModels.cs:12
   AutoParkManager.Controllers.AccountController..ctor() in c:\AppVS2013\AutoPark\AutoParkManager\Controllers\AccountController.cs:22

[TargetInvocationException: Exception has been thrown by the target of an invocation.]
   System.RuntimeTypeHandle.CreateInstance(RuntimeType type, Boolean publicOnly, Boolean noCheck, Boolean& canBeCached, RuntimeMethodHandleInternal& ctor, Boolean& bNeedSecurityCheck) +0
   System.RuntimeType.CreateInstanceSlow(Boolean publicOnly, Boolean skipCheckThis, Boolean fillCache, StackCrawlMark& stackMark) +159
   System.RuntimeType.CreateInstanceDefaultCtor(Boolean publicOnly, Boolean skipCheckThis, Boolean fillCache, StackCrawlMark& stackMark) +256
   System.Activator.CreateInstance(Type type, Boolean nonPublic) +127
   System.Activator.CreateInstance(Type type) +11
   System.Web.Mvc.DefaultControllerActivator.Create(RequestContext requestContext, Type controllerType) +92

[InvalidOperationException: An error occurred when trying to create a controller of type 'AutoParkManager.Controllers.AccountController'. Make sure that the controller has a parameterless public constructor.]
   System.Web.Mvc.DefaultControllerActivator.Create(RequestContext requestContext, Type controllerType) +256
   System.Web.Mvc.DefaultControllerFactory.CreateController(RequestContext requestContext, String controllerName) +169
   System.Web.Mvc.MvcHandler.ProcessRequestInit(HttpContextBase httpContext, IController& controller, IControllerFactory& factory) +270
   System.Web.Mvc.MvcHandler.BeginProcessRequest(HttpContextBase httpContext, AsyncCallback callback, Object state) +147
   System.Web.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +12639055
   System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +288

2 个答案:

答案 0 :(得分:1)

如下所示更改connectionstring,然后重试。取消Integrated Security=false;并指定Persist Security Info=True;

 <add name="AutoPark" connectionString="Data Source=(LocalDb)\v11.0;Initial Catalog=AutoParkDemo;Persist Security Info=True;user=apmDemo;pwd=*****" providerName="System.Data.SqlClient" />

答案 1 :(得分:0)

更好的解决方案是在服务器上创建新的本地Windows用户,将该用户添加到SQL数据库(具有正确的权限)。然后使用此新标识创建一个新的应用程序池,并使用此新应用程序池将一个网站进行分配。您可以将Integrate Security保留为True。

如果你真的想在配置中指定用户,那么Martin和Dennis评论我们需要完整的错误消息和连接字符串(减去密码)