Eric Bishard
Eric Bishard

Reputation: 5331

Where do I stick my azure connection string

My publish settings were suppose to add it when I use the Import feature from azue and select the sql DB I want to use with code first? But it didn't set a connection string in my web.config should it be in my web.release.config? so confused. Here is the connection strig I got from azure, but I don't know where to put it...

Server=tcp:xxxxemxxx1.database.windows.net,1433;Database=XXX;User ID=XXXinc@xxxxemxxx1;Password=XXXXXX8XX!;Trusted_Connection=False;Encrypt=True;Connection Timeout=30;

Do I replace my local default connection string? If so then why do the publish settings have me pick my SQL Server DB? I also checked under the CONNECTION tab in Publish dialogue box and everything was populated as I would expect. I switch to the SETTINGS tab in Publish and select under Databases my corresponding SQL Server and check the two boxes:

[x] Use this connection string at runtime (update destination web.config) [x] Execute COde FIrst Migrations (runs on application start)

So far so good, everything gets uploaded and the site appears to work fine until I use the login feature (ASP.NET Identity-MVC 5). This is it's first dealing with the Database and I get the following error from the url: https://mywebsite.azurewebsites.net/Account/Login

Format of the initialization string does not conform to specification starting at index 0.

Here is the Stack Trace:

[ArgumentException: Format of the initialization string does not conform to specification starting at index 0.]
   System.Data.Common.DbConnectionOptions.GetKeyValuePair(String connectionString, Int32 currentPosition, StringBuilder buffer, Boolean useOdbcRules, String& keyname, String& keyvalue) +5314705
   System.Data.Common.DbConnectionOptions.ParseInternal(Hashtable parsetable, String connectionString, Boolean buildChain, Hashtable synonyms, Boolean firstKey) +124
   System.Data.Common.DbConnectionOptions..ctor(String connectionString, Hashtable synonyms, Boolean useOdbcRules) +95
   System.Data.SqlClient.SqlConnectionString..ctor(String connectionString) +59
   System.Data.SqlClient.SqlConnectionFactory.CreateConnectionOptions(String connectionString, DbConnectionOptions previous) +24
   System.Data.ProviderBase.DbConnectionFactory.GetConnectionPoolGroup(DbConnectionPoolKey key, DbConnectionPoolGroupOptions poolOptions, DbConnectionOptions& userConnectionOptions) +167
   System.Data.SqlClient.SqlConnection.ConnectionString_Set(DbConnectionPoolKey key) +61
   System.Data.SqlClient.SqlConnection.set_ConnectionString(String value) +66
   System.Data.Entity.Internal.LazyInternalConnection.InitializeFromConnectionStringSetting(ConnectionStringSettings appConfigConnection) +122
   System.Data.Entity.Internal.LazyInternalConnection.TryInitializeFromAppConfig(String name, AppConfig config) +32
   System.Data.Entity.Internal.LazyInternalConnection.Initialize() +127
   System.Data.Entity.Internal.LazyInternalConnection.get_ProviderName() +13
   System.Data.Entity.Internal.LazyInternalContext.get_ProviderName() +11
   System.Data.Entity.Internal.DefaultModelCacheKeyFactory.Create(DbContext context) +91
   System.Data.Entity.Internal.LazyInternalContext.InitializeContext() +499
   System.Data.Entity.Internal.InternalContext.GetEntitySetAndBaseTypeForType(Type entityType) +18
   System.Data.Entity.Internal.Linq.InternalSet`1.Initialize() +53
   System.Data.Entity.Internal.Linq.InternalSet`1.get_InternalContext() +15
   System.Data.Entity.Infrastructure.DbQuery`1.System.Linq.IQueryable.get_Provider() +38
   System.Linq.Queryable.Where(IQueryable`1 source, Expression`1 predicate) +63
   Microsoft.AspNet.Identity.EntityFramework.UserStore`1.FindByNameAsync(String userName) +617
   Microsoft.AspNet.Identity.<FindByNameAsync>d__d.MoveNext() +102
   System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) +93
   System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) +52
   Microsoft.AspNet.Identity.<FindAsync>d__15.MoveNext() +244
   System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) +93
   System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) +52
   MYWEBSITE.Controllers.<Login>d__2.MoveNext() +244
   System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) +93
   System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) +52
   lambda_method(Closure , Task ) +23
   System.Threading.Tasks.TaskHelpersExtensions.ThrowIfFaulted(Task task) +33
   System.Web.Mvc.Async.TaskAsyncActionDescriptor.EndExecute(IAsyncResult asyncResult) +68
   System.Web.Mvc.Async.<>c__DisplayClass34.<BeginInvokeAsynchronousActionMethod>b__33(IAsyncResult asyncResult) +16
   System.Web.Mvc.Async.WrappedAsyncResult`1.CallEndDelegate(IAsyncResult asyncResult) +10
   System.Web.Mvc.Async.WrappedAsyncResultBase`1.End() +49
   System.Web.Mvc.Async.AsyncControllerActionInvoker.EndInvokeActionMethod(IAsyncResult asyncResult) +32
   System.Web.Mvc.Async.AsyncInvocationWithFilters.<InvokeActionMethodFilterAsynchronouslyRecursive>b__3c() +50
   System.Web.Mvc.Async.<>c__DisplayClass45.<InvokeActionMethodFilterAsynchronouslyRecursive>b__3e() +225
   System.Web.Mvc.Async.<>c__DisplayClass30.<BeginInvokeActionMethodWithFilters>b__2f(IAsyncResult asyncResult) +10
   System.Web.Mvc.Async.WrappedAsyncResult`1.CallEndDelegate(IAsyncResult asyncResult) +10
   System.Web.Mvc.Async.WrappedAsyncResultBase`1.End() +49
   System.Web.Mvc.Async.AsyncControllerActionInvoker.EndInvokeActionMethodWithFilters(IAsyncResult asyncResult) +34
   System.Web.Mvc.Async.<>c__DisplayClass28.<BeginInvokeAction>b__19() +26
   System.Web.Mvc.Async.<>c__DisplayClass1e.<BeginInvokeAction>b__1b(IAsyncResult asyncResult) +100
   System.Web.Mvc.Async.WrappedAsyncResult`1.CallEndDelegate(IAsyncResult asyncResult) +10
   System.Web.Mvc.Async.WrappedAsyncResultBase`1.End() +49
   System.Web.Mvc.Async.AsyncControllerActionInvoker.EndInvokeAction(IAsyncResult asyncResult) +27
   System.Web.Mvc.Controller.<BeginExecuteCore>b__1d(IAsyncResult asyncResult, ExecuteCoreState innerState) +13
   System.Web.Mvc.Async.WrappedAsyncVoid`1.CallEndDelegate(IAsyncResult asyncResult) +36
   System.Web.Mvc.Async.WrappedAsyncResultBase`1.End() +54
   System.Web.Mvc.Controller.EndExecuteCore(IAsyncResult asyncResult) +39
   System.Web.Mvc.Controller.<BeginExecute>b__15(IAsyncResult asyncResult, Controller controller) +12
   System.Web.Mvc.Async.WrappedAsyncVoid`1.CallEndDelegate(IAsyncResult asyncResult) +28
   System.Web.Mvc.Async.WrappedAsyncResultBase`1.End() +54
   System.Web.Mvc.Controller.EndExecute(IAsyncResult asyncResult) +29
   System.Web.Mvc.Controller.System.Web.Mvc.Async.IAsyncController.EndExecute(IAsyncResult asyncResult) +10
   System.Web.Mvc.MvcHandler.<BeginProcessRequest>b__4(IAsyncResult asyncResult, ProcessRequestState innerState) +21
   System.Web.Mvc.Async.WrappedAsyncVoid`1.CallEndDelegate(IAsyncResult asyncResult) +36
   System.Web.Mvc.Async.WrappedAsyncResultBase`1.End() +54
   System.Web.Mvc.MvcHandler.EndProcessRequest(IAsyncResult asyncResult) +31
   System.Web.Mvc.MvcHandler.System.Web.IHttpAsyncHandler.EndProcessRequest(IAsyncResult result) +9
   System.Web.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +9631764
   System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +155

I have wasted hours on this, I have read many questions here on StackExchange. I don't know how to check the Web.Config file that Visual Studio uploads to the Azure website in order to see if it is correct. But Azure dictates all of this in the publish settings right? It should work???

My web.config on my machine has the standard DEFAULT CONNECTION STRING:

<add name="DefaultConnection" connectionString="Data Source=(LocalDb)\v11.0;Initial Catalog=aspnet-MYWEBSITENAME-201312290500266;Integrated Security=SSPI;AttachDBFilename=|DataDirectory|\aspnet-MYWEBSITENAME-201312290500266.mdf" providerName="System.Data.SqlClient"/>

Upvotes: 0

Views: 647

Answers (1)

JYL
JYL

Reputation: 8319

Go to the Azure portal, on the configure tab :

Configure tab

And set the connection string here, it will override the web.config file :

enter image description here

EDIT : just saw the format of your connection string in your question.

Yours is :

Server=tcp:xxxxemxxx1.database.windows.net,1433;Database=XXX;User ID=XXXinc@xxxxemxxx1;Password=XXXXXX8XX!;Trusted_Connection=False;Encrypt=True;Connection Timeout=30;

Mine is :

Data Source= tcp:myServerName.database.windows.net,1433;Initial Catalog= myDatabaseName; User ID= myUserName@myServerName;Password=myPasswordHere;

Upvotes: 2

Related Questions