ASP.Net MVC3 SQL连接字符串

6

我正在APPHARBOR上创建一个应用程序,并且我有一个实体模型用于查询SQL服务器。以下字符串给我带来了错误:

<add name="TraxzDBEntities" 
           connectionString="metadata=res://*/Models.DBModel.csdl|res://*/Models.DBModel.ssdl|res://*/Models.DBModel.msl;
           provider=System.Data.SqlClient;
           provider connection string='Data Source=d5d3955e-1183-4e10-8892-9f9d005af0a8.sqlserver.sequelizer.com;
           User ID=**; 
           Password=**;
           Initial Catalog=dbd5d3955e11834e1088929f9d005af0a8;Integrated Security=true;
           MultipleActiveResultSets=True'"
      providerName="System.Data.EntityClient" />

以下是堆栈跟踪: 描述:当前网络请求的执行过程中发生了一个未处理的异常。请查看堆栈跟踪以获取有关错误及其在代码中的来源的更多信息。
异常详情:System.ArgumentException: 不支持的关键字:“server”。
源错误:
当前网络请求的执行过程中生成了一个未处理的异常。可以使用下面的异常堆栈跟踪来确定异常的起源和位置。
[ArgumentException: Keyword not supported: 'server'.]
   System.Data.Common.DbConnectionOptions.ParseInternal(Hashtable parsetable, String connectionString, Boolean buildChain, Hashtable synonyms, Boolean firstKey) +5110868
   System.Data.Common.DbConnectionOptions..ctor(String connectionString, Hashtable synonyms, Boolean useOdbcRules) +98
   System.Data.EntityClient.EntityConnection.ChangeConnectionString(String newConnectionString) +112
   System.Data.EntityClient.EntityConnection..ctor(String connectionString) +77
   System.Data.Entity.Internal.LazyInternalConnection.TryInitializeFromAppConfig(String name, ConnectionStringSettingsCollection connectionStrings) +309
   System.Data.Entity.Internal.LazyInternalConnection.Initialize() +52
   System.Data.Entity.Internal.LazyInternalConnection.get_ConnectionHasModel() +10
   System.Data.Entity.Internal.LazyInternalContext.InitializeContext() +265
   System.Data.Entity.Internal.InternalContext.GetEntitySetAndBaseTypeForType(Type entityType) +18
   System.Data.Entity.Internal.Linq.InternalSet`1.Initialize() +62
   System.Data.Entity.Internal.Linq.InternalSet`1.get_InternalContext() +15
   System.Data.Entity.Infrastructure.DbQuery`1.System.Linq.IQueryable.get_Provider() +37
   System.Linq.Queryable.Where(IQueryable`1 source, Expression`1 predicate) +63
   Traxz.Models.TraxzRepository.getListOfUserExerciseSessions(Guid userID) in d:\temp\lhvy3m2t.j0d\input\Traxz\Models\TraxzRepository.cs:77
   Traxz.Controllers.ExerciseSessionController.listSessions(Nullable`1 page, Nullable`1 SessionID) in d:\temp\lhvy3m2t.j0d\input\Traxz\Controllers\ExerciseSessionController.cs:34
   lambda_method(Closure , ControllerBase , Object[] ) +164
   System.Web.Mvc.ActionMethodDispatcher.Execute(ControllerBase controller, Object[] parameters) +17
   System.Web.Mvc.ReflectedActionDescriptor.Execute(ControllerContext controllerContext, IDictionary`2 parameters) +208
   System.Web.Mvc.ControllerActionInvoker.InvokeActionMethod(ControllerContext controllerContext, ActionDescriptor actionDescriptor, IDictionary`2 parameters) +27
   System.Web.Mvc.<>c__DisplayClass15.<InvokeActionMethodWithFilters>b__12() +55
   System.Web.Mvc.ControllerActionInvoker.InvokeActionMethodFilter(IActionFilter filter, ActionExecutingContext preContext, Func`1 continuation) +263
   System.Web.Mvc.<>c__DisplayClass17.<InvokeActionMethodWithFilters>b__14() +19
   System.Web.Mvc.ControllerActionInvoker.InvokeActionMethodWithFilters(ControllerContext controllerContext, IList`1 filters, ActionDescriptor actionDescriptor, IDictionary`2 parameters) +191
   System.Web.Mvc.ControllerActionInvoker.InvokeAction(ControllerContext controllerContext, String actionName) +343
   System.Web.Mvc.Controller.ExecuteCore() +116
   System.Web.Mvc.ControllerBase.Execute(RequestContext requestContext) +97
   System.Web.Mvc.ControllerBase.System.Web.Mvc.IController.Execute(RequestContext requestContext) +10
   System.Web.Mvc.<>c__DisplayClassb.<BeginProcessRequest>b__5() +37
   System.Web.Mvc.Async.<>c__DisplayClass1.<MakeVoidDelegate>b__0() +21
   System.Web.Mvc.Async.<>c__DisplayClass8`1.<BeginSynchronous>b__7(IAsyncResult _) +12
   System.Web.Mvc.Async.WrappedAsyncResult`1.End() +62
   System.Web.Mvc.<>c__DisplayClasse.<EndProcessRequest>b__d() +50
   System.Web.Mvc.SecurityUtil.<GetCallInAppTrustThunk>b__0(Action f) +7
   System.Web.Mvc.SecurityUtil.ProcessInApplicationTrust(Action action) +22
   System.Web.Mvc.MvcHandler.EndProcessRequest(IAsyncResult asyncResult) +60
   System.Web.Mvc.MvcHandler.System.Web.IHttpAsyncHandler.EndProcessRequest(IAsyncResult result) +9
   System.Web.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +8963149
   System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +184

我在这上面浪费了很多时间,但是不知道哪里出了差错.. 请帮忙解决。

2个回答

4

这里似乎使用了其他的连接字符串。你在代码中是否也设置了连接字符串? 在你的asp.net mvc项目中,web.config文件中所有的连接字符串都是什么?只有上面提到的吗?

搜索整个解决方案中包含"server"一词的内容。


同意,我也遇到过这种情况,最终发现是设计器引用了不同的连接字符串。 - Chris Townsend
我已经阅读了一些有关AppHarbor的文档,看起来他们强制你构建一个动态连接字符串--但是我已经测试了这个字符串,它可以正确地查询托管的SQL服务器。 - Aziz
那么你遗漏了重要的细节。这个动态连接字符串是什么?我敢说它由于上述错误而无法正常工作。 - Adam Tuliper

1
补充一下Adam的建议(可能是答案),在你的代码片段中,Password=**后面没有;(也许在实际代码中有)。而且你同时使用了用户名和密码以及Integrated Security=true;,这对我来说没有意义,因为Integrated Security=true;表示使用当前登录的用户。

我尝试删除 Integrated Security=true; -- 但是这没有任何效果。 - Aziz

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接