0

I'm using Amazon Web Services to deploy my first C# application. Testing with Visual Studio on localhost, the program works perfectly, but the Exception System.Data.SqlClient.SqlException: Login failed for user 'dbuser'. is thrown after attempting to run on the deployment server. The application environment (Elastic Beanstalk) runs 64bit Windows Server 2012 R2 v1.2.0 running IIS 8.5, the database runs SQL Server Express 11.00.2100.60.v1, and the Instance Class runs the Micro db.t2.small. The deployed file is the .sln Microsoft Visual Studio Solution file in the application's main folder.

The other SO questions on this same topic seem solved by either using Forms authentication, ensuring the database username and password are correct, or setting integrated security=False; - all of which appear to have been done. Does anyone know what else could be causing this? Thanks in advance!

Stack Trace:

[SqlException (0x80131904): Login failed for user 'dbuser'.]
    System.Data.ProviderBase.DbConnectionPool.TryGetConnection(DbConnection owningObject, UInt32 waitForMultipleObjectsTimeout, Boolean allowCreate, Boolean onlyOneCheckConnection, DbConnectionOptions userOptions, DbConnectionInternal& connection) +356
    System.Data.ProviderBase.DbConnectionPool.TryGetConnection(DbConnection owningObject, TaskCompletionSource`1 retry, DbConnectionOptions userOptions, DbConnectionInternal& connection) +117
    System.Data.ProviderBase.DbConnectionFactory.TryGetConnection(DbConnection owningConnection, TaskCompletionSource`1 retry, DbConnectionOptions userOptions, DbConnectionInternal oldConnection, DbConnectionInternal& connection) +267
    System.Data.ProviderBase.DbConnectionInternal.TryOpenConnectionInternal(DbConnection outerConnection, DbConnectionFactory connectionFactory, TaskCompletionSource`1 retry, DbConnectionOptions userOptions) +318
    System.Data.SqlClient.SqlConnection.TryOpenInner(TaskCompletionSource`1 retry) +132
    System.Data.SqlClient.SqlConnection.TryOpen(TaskCompletionSource`1 retry) +246
    System.Data.SqlClient.SqlConnection.Open() +122
    System.Data.Entity.Infrastructure.Interception.InternalDispatcher`1.Dispatch(TTarget target, Action`2 operation, TInterceptionContext interceptionContext, Action`3 executing, Action`3 executed) +104
    System.Data.Entity.Infrastructure.Interception.DbConnectionDispatcher.Open(DbConnection connection, DbInterceptionContext interceptionContext) +509
    System.Data.Entity.SqlServer.<>c__DisplayClass33.<UsingConnection>b__32() +567
    System.Data.Entity.SqlServer.<>c__DisplayClass1.<Execute>b__0() +15
    System.Data.Entity.SqlServer.DefaultSqlExecutionStrategy.Execute(Func`1 operation) +238
    System.Data.Entity.SqlServer.SqlProviderServices.UsingMasterConnection(DbConnection sqlConnection, Action`1 act) +916
    System.Data.Entity.SqlServer.SqlProviderServices.CreateDatabaseFromScript(Nullable`1 commandTimeout, DbConnection sqlConnection, String createDatabaseScript) +117
    System.Data.Entity.SqlServer.SqlProviderServices.DbCreateDatabase(DbConnection connection, Nullable`1 commandTimeout, StoreItemCollection storeItemCollection) +212
    System.Data.Entity.Migrations.Utilities.DatabaseCreator.Create(DbConnection connection) +135
    System.Data.Entity.Migrations.DbMigrator.EnsureDatabaseExists(Action mustSucceedToKeepDatabase) +175
    System.Data.Entity.Migrations.DbMigrator.Update(String targetMigration) +116
    System.Data.Entity.Internal.DatabaseCreator.CreateDatabase(InternalContext internalContext, Func`3 createMigrator, ObjectContext objectContext) +121
    System.Data.Entity.Database.Create(DatabaseExistenceState existenceState) +293
    System.Web.Providers.ModelHelper.EnsureDatabaseCreated(DbContext db) +110
    System.Web.Providers.ModelHelper.CreateMembershipContext(ConnectionStringSettings setting) +83
    System.Web.Providers.DefaultMembershipProvider.ValidateUser(String username, String password) +122
    Db.Controllers.AccountController.ValidateLogOn(String userName, String password) +395
    Db.Controllers.AccountController.LogOn(String userName, String password, Boolean rememberMe, String returnUrl) +33
    lambda_method(Closure , ControllerBase , Object[] ) +298
    System.Web.Mvc.ReflectedActionDescriptor.Execute(ControllerContext controllerContext, IDictionary`2 parameters) +209
    System.Web.Mvc.ControllerActionInvoker.InvokeActionMethod(ControllerContext controllerContext, ActionDescriptor actionDescriptor, IDictionary`2 parameters) +35
    System.Web.Mvc.Async.AsyncControllerActionInvoker.<BeginInvokeSynchronousActionMethod>b__39(IAsyncResult asyncResult, ActionInvocation innerInvokeState) +39
    System.Web.Mvc.Async.WrappedAsyncResult`2.CallEndDelegate(IAsyncResult asyncResult) +71
    System.Web.Mvc.Async.AsyncControllerActionInvoker.EndInvokeActionMethod(IAsyncResult asyncResult) +42
    System.Web.Mvc.Async.AsyncInvocationWithFilters.<InvokeActionMethodFilterAsynchronouslyRecursive>b__3d() +72
    System.Web.Mvc.Async.<>c__DisplayClass46.<InvokeActionMethodFilterAsynchronouslyRecursive>b__3f() +386
    System.Web.Mvc.Async.AsyncControllerActionInvoker.EndInvokeActionMethodWithFilters(IAsyncResult asyncResult) +42
    System.Web.Mvc.Async.<>c__DisplayClass2b.<BeginInvokeAction>b__1c() +30
    System.Web.Mvc.Async.<>c__DisplayClass21.<BeginInvokeAction>b__1e(IAsyncResult asyncResult) +186
    System.Web.Mvc.Async.AsyncControllerActionInvoker.EndInvokeAction(IAsyncResult asyncResult) +38
    System.Web.Mvc.Controller.<BeginExecuteCore>b__1d(IAsyncResult asyncResult, ExecuteCoreState innerState) +29
    System.Web.Mvc.Async.WrappedAsyncVoid`1.CallEndDelegate(IAsyncResult asyncResult) +67
    System.Web.Mvc.Controller.EndExecuteCore(IAsyncResult asyncResult) +53
    System.Web.Mvc.Async.WrappedAsyncVoid`1.CallEndDelegate(IAsyncResult asyncResult) +36
    System.Web.Mvc.Controller.EndExecute(IAsyncResult asyncResult) +38
    System.Web.Mvc.MvcHandler.<BeginProcessRequest>b__5(IAsyncResult asyncResult, ProcessRequestState innerState) +44
    System.Web.Mvc.Async.WrappedAsyncVoid`1.CallEndDelegate(IAsyncResult asyncResult) +67
    System.Web.Mvc.MvcHandler.EndProcessRequest(IAsyncResult asyncResult) +38
    System.Web.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +399
    System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +157

Web.config Connection Strings:

<connectionStrings>
     <add name="DbEntities" connectionString="metadata=[metadata];provider=System.Data.SqlClient;provider connection string=&quot;data source=[data source].rds.amazonaws.com;initial catalog=Db;integrated security=False;user id=Dbuser;password=[password];MultipleActiveResultSets=True;App=EntityFramework&quot;" providerName="System.Data.EntityClient" />
     <add name="UserDbEntities" connectionString="metadata=[metadata];provider=System.Data.SqlClient;provider connection string=&quot;data source=[data source].rds.amazonaws.com;initial catalog=UserDb;integrated security=False;user id=Dbuser;password=[password];connect timeout=30;MultipleActiveResultSets=True;App=EntityFramework&quot;" providerName="System.Data.EntityClient" />
     <add name="DefaultConnection" providerName="System.Data.SqlClient" connectionString="Server=[server].rds.amazonaws.com;Database=UserDb;User ID=Dbuser;Password=[password];Trusted_Connection=False;Connection Timeout=30;" />
</connectionStrings>
Community
  • 1
  • 1
jle
  • 269
  • 8
  • 25

2 Answers2

0

In Sql Server, user accounts and credetials are set at the server level, not at the database level. When you deploy an SQL database, only the database info moves over. You need to connect to the DB Server in your deployed environment, set up the username and password you want to use, and give the account appropriate permissions into the database.

Joel Coehoorn
  • 399,467
  • 113
  • 570
  • 794
  • Thanks for the response, Joel! The user ID in the connection strings refers to a user under the Server\Security\Logins in SQL. Is that connected at the server level? Also, is the server-level user not affecting the localhost, thus testing is successful? – jle Nov 28 '16 at 17:06
  • That is defined at the server level. If you set that up on your development system, you need to set it up again manually in production. It won't just move over with your database. And it's not enough to just create the account. You must grant the account permissions on the database. – Joel Coehoorn Nov 28 '16 at 17:48
  • Thanks again Joel, but I'm not sure I understand. Nothing was moved, per se. The database with read/write access and the environment on AWS are the same, I just uploaded the app's .sln file to the "Upload and Deploy" before associating it with a CNAME. All of the server security users in AWS and the database are unchanged and should still be used by the application, right? – jle Nov 28 '16 at 20:06
  • That's not it at all. You need more than a solution file to upload an app. A solution file just describes all the other files in the project and the steps to take to build it. Additionally, the database you connected to while building your application is not likely to already be hosted at Amazon. – Joel Coehoorn Nov 28 '16 at 21:17
  • Ah, thank you! I'll look for what else needs to be uploaded besides just the .sln file. The hosting environment and database are also hosted by Amazon, so I think this piece is all that I'm missing. I'll return with an update when I find what all needs to be uploaded besides the solution file. – jle Nov 28 '16 at 22:22
  • Your last comment did the trick! I used a deployment package instead of just the .sln file, and everything works! If you woulnd't mind changing the answer to reflect that last comment, I'd be happy to mark it correct! – jle Dec 05 '16 at 14:51
0

The answer here turned out to be that deploying only the .sln file is insufficient. I tried to create and upload a deployment package, but that didn't work, either. I had the AWS Toolkit for Visual Studio, and noticed a "Deploy to AWS" option when right-clicking the project file in VS. After clicking that and following the steps, everything worked fine.

jle
  • 269
  • 8
  • 25