我在哪里粘贴我的天蓝色连接字符串

时间:2013-12-29 21:41:10

标签: c# sql-server azure connection-string asp.net-mvc-5

当我使用azue的导入功能并选择我想首先使用的sql DB时,我的发布设置是假设要添加的吗?但它没有在我的web.config中设置连接字符串,如果它在我的web.release.config中?如此迷茫。这是我从azure得到的连接strig,但我不知道把它放在哪里......

  

服务器= TCP:xxxxemxxx1.database.windows.net,1433;数据库= XXX;用户   ID = XXXinc @ xxxxemxxx1;密码= XXXXXX8XX;!Trusted_Connection = FALSE;加密= TRUE;连接   超时= 30;

我是否替换了本地默认连接字符串?如果是这样,为什么发布设置让我选择我的SQL Server数据库?我还在“发布”对话框的“连接”选项卡下进行了检查,所有内容都按照我的预期填充。我切换到Publish中的SETTINGS选项卡,然后在Databases下选择我对应的SQL Server并选中两个框:

[x]在运行时使用此连接字符串(更新目标web.config) [x]执行COde FIrst Migrations(在应用程序启动时运行)

到目前为止一切都很好,一切都上传了,网站似乎工作正常,直到我使用登录功能(ASP.NET Identity-MVC 5)。这是它第一次处理数据库,我从网址得到以下错误:https://mywebsite.azurewebsites.net/Account/Login

  

初始化字符串的格式不符合规范   从索引0开始。

这是堆栈跟踪:

[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

我浪费了几个小时,我在StackExchange上看了很多问题。我不知道如何检查Visual Studio上传到Azure网站的Web.Config文件,以查看它是否正确。但Azure在发布设置中规定了所有这些吗?它应该工作???

我的机器上的web.config具有标准的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"/>

1 个答案:

答案 0 :(得分:2)

转到Azure门户,在配置选项卡上:

Configure tab

在此处设置连接字符串,它将覆盖web.config文件:

enter image description here

编辑:在您的问题中看到了连接字符串的格式。

你的是:

  

服务器= TCP:xxxxemxxx1.database.windows.net,1433;数据库= XXX;用户   ID = XXXinc @ xxxxemxxx1;密码= XXXXXX8XX;!Trusted_Connection = FALSE;加密= TRUE;连接   超时= 30;

我的是:

  

数据源= tcp:myServerName.database.windows.net,1433; 初始目录= myDatabaseName;用户ID =   名为myUsername @ myServerName;密码= myPasswordHere;