0

我刚刚为我的网络应用程序创建了一些托管空间。但是,当我将连接字符串更改为指向我的提供商的 SQL 服务器时,我收到一个错误。

字符串如下:

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

我收到这个奇怪的错误:

Login failed for user 'juydqjglrdwrhgsr'.

Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. 

Exception Details: System.Data.SqlClient.SqlException: Login failed for user 'juydqjglrdwrhgsr'.

Source Error: 


Line 32:                     <li>@Html.ActionLink("Home", "Index", "Home")</li>
Line 33:                     @{
Line 34:                         if(User.IsInRole("Admin"))
Line 35:                         {
Line 36:                          <li>@Html.ActionLink("Admin Controls", "Index", "Admin")</li> 

Source File: c:\Users\Administrator\Documents\Visual Studio 2010\Projects\Traxz\Traxz\Views\Shared\_Layout.cshtml    Line: 34 

Stack Trace: 


[SqlException (0x80131904): Login failed for user 'juydqjglrdwrhgsr'.]
   System.Data.SqlClient.SqlInternalConnection.OnError(SqlException exception, Boolean breakConnection) +5064474
   System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning() +234
   System.Data.SqlClient.TdsParser.Run(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj) +2275
   System.Data.SqlClient.SqlInternalConnectionTds.CompleteLogin(Boolean enlistOK) +35
   System.Data.SqlClient.SqlInternalConnectionTds.AttemptOneLogin(ServerInfo serverInfo, String newPassword, Boolean ignoreSniOpenTimeout, TimeoutTimer timeout, SqlConnection owningObject) +183
   System.Data.SqlClient.SqlInternalConnectionTds.LoginNoFailover(ServerInfo serverInfo, String newPassword, Boolean redirectedUserInstance, SqlConnection owningObject, SqlConnectionString connectionOptions, TimeoutTimer timeout) +239
   System.Data.SqlClient.SqlInternalConnectionTds.OpenLoginEnlist(SqlConnection owningObject, TimeoutTimer timeout, SqlConnectionString connectionOptions, String newPassword, Boolean redirectedUserInstance) +195
   System.Data.SqlClient.SqlInternalConnectionTds..ctor(DbConnectionPoolIdentity identity, SqlConnectionString connectionOptions, Object providerInfo, String newPassword, SqlConnection owningObject, Boolean redirectedUserInstance) +232
   System.Data.SqlClient.SqlConnectionFactory.CreateConnection(DbConnectionOptions options, Object poolGroupProviderInfo, DbConnectionPool pool, DbConnection owningConnection) +185
   System.Data.ProviderBase.DbConnectionFactory.CreatePooledConnection(DbConnection owningConnection, DbConnectionPool pool, DbConnectionOptions options) +33
   System.Data.ProviderBase.DbConnectionPool.CreateObject(DbConnection owningObject) +524
   System.Data.ProviderBase.DbConnectionPool.UserCreateRequest(DbConnection owningObject) +66
   System.Data.ProviderBase.DbConnectionPool.GetConnection(DbConnection owningObject) +479
   System.Data.ProviderBase.DbConnectionFactory.GetConnection(DbConnection owningConnection) +108
   System.Data.ProviderBase.DbConnectionClosed.OpenConnection(DbConnection outerConnection, DbConnectionFactory connectionFactory) +126
   System.Data.SqlClient.SqlConnection.Open() +125
   System.Web.DataAccess.SqlConnectionHolder.Open(HttpContext context, Boolean revertImpersonate) +95
   System.Web.DataAccess.SqlConnectionHelper.GetConnection(String connectionString, Boolean revertImpersonation) +206
   System.Web.Security.SqlRoleProvider.GetRolesForUser(String username) +847
   WebMatrix.WebData.SimpleRoleProvider.GetRolesForUser(String username) +58
   System.Web.Security.RolePrincipal.IsInRole(String role) +182
   ASP._Page_Views_Shared__Layout_cshtml.Execute() in c:\Users\Administrator\Documents\Visual Studio 2010\Projects\Traxz\Traxz\Views\Shared\_Layout.cshtml:34
   System.Web.WebPages.WebPageBase.ExecutePageHierarchy() +272
   System.Web.Mvc.WebViewPage.ExecutePageHierarchy() +81
   System.Web.WebPages.WebPageBase.ExecutePageHierarchy(WebPageContext pageContext, TextWriter writer, WebPageRenderingBase startPage) +187
   System.Web.WebPages.WebPageBase.ExecutePageHierarchy(WebPageContext pageContext, TextWriter writer) +52
   System.Web.WebPages.<>c__DisplayClass7.<RenderPageCore>b__6(TextWriter writer) +203
   System.Web.WebPages.HelperResult.WriteTo(TextWriter writer) +42
   System.Web.WebPages.WebPageExecutingBase.WriteTo(TextWriter writer, HelperResult content) +45
   System.Web.WebPages.WebPageBase.Write(HelperResult result) +48
   System.Web.WebPages.WebPageBase.RenderSurrounding(String partialViewName, Action`1 body) +178
   System.Web.WebPages.WebPageBase.PopContext() +338
   System.Web.WebPages.WebPageBase.ExecutePageHierarchy(WebPageContext pageContext, TextWriter writer, WebPageRenderingBase startPage) +196
   System.Web.Mvc.RazorView.RenderView(ViewContext viewContext, TextWriter writer, Object instance) +220
   System.Web.Mvc.BuildManagerCompiledView.Render(ViewContext viewContext, TextWriter writer) +115
   System.Web.Mvc.ViewResultBase.ExecuteResult(ControllerContext context) +303
   System.Web.Mvc.ControllerActionInvoker.InvokeActionResult(ControllerContext controllerContext, ActionResult actionResult) +13
   System.Web.Mvc.<>c__DisplayClass1c.<InvokeActionResultWithFilters>b__19() +23
   System.Web.Mvc.ControllerActionInvoker.InvokeActionResultFilter(IResultFilter filter, ResultExecutingContext preContext, Func`1 continuation) +260
   System.Web.Mvc.<>c__DisplayClass1e.<InvokeActionResultWithFilters>b__1b() +19
   System.Web.Mvc.ControllerActionInvoker.InvokeActionResultWithFilters(ControllerContext controllerContext, IList`1 filters, ActionResult actionResult) +177
   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

我假设连接字符串做错了什么,任何人都可以对此有所了解吗?需要启动并运行此托管才能继续我的学校项目。:)

更新:我正在使用 AppHarbor 进行托管,我一直在寻找这个问题并发现了这个:

  If you take advantage of the Sequelizer MySQL and MS SQL Server add-ons, SQLSERVER_CONNECTION_STRING and SQLSERVER_URI settings will be injected into your application appSettings. SQLSERVER_CONNECTION_STRING_ALIAS will also be inserted if you add an alias. Further, the connection string will be placed in the connectionStrings element with name set to the alias if one is specified.

The uri is of the following format: sqlserver://username:password@hostname/databasename. If you want, you can create your own connection string (if, for example, you need a custom one for Entity Framework). Here's an example of building a standard connection string:

var uriString = ConfigurationManager.AppSettings["SQLSERVER_URI"];
var uri = new Uri(uriString);
var connectionString = new SqlConnectionStringBuilder
{
    DataSource = uri.Host,
    InitialCatalog = uri.AbsolutePath.Trim('/'),
    UserID = uri.UserInfo.Split(':').First(),
    Password = uri.UserInfo.Split(':').Last(),
}.ConnectionString;

我不知道这到底意味着什么。我需要添加一个新的连接字符串吗?如果是这样,我如何创建一个映射到我创建的实体?

4

1 回答 1

0

通过修改 applicationServices 连接字符串修复了该问题:

<add name="TraxzDBEntities" connectionString="metadata=res://*/Models.DBModel.csdl|res://*/Models.DBModel.ssdl|res://*/Models.DBModel.msl;&#xD;&#xA;         provider=System.Data.SqlClient;&#xD;&#xA;         provider connection string=&quot;&#xD;&#xA;         Data Source=YOURPROVIDERDATASOURCE;&#xD;&#xA;         User ID=YourUserName; &#xD;&#xA;         Password=YourPassword;&#xD;&#xA;         Initial Catalog=YourCatalog;&#xD;&#xA;         Persist Security Info=True;&#xD;&#xA;      MultipleActiveResultSets=True&quot;" providerName="System.Data.EntityClient" />

然后在我的 .tt 类下它是“Dbcontext.context.tt”,我们添加以下内容

   string baseConnectionString = ConfigurationManager.ConnectionStrings["TraxzDBEntities"].ConnectionString;

    EntityConnectionStringBuilder entityBuilder = new EntityConnectionStringBuilder();
    entityBuilder.Provider = "System.Data.SqlClient";
    entityBuilder.ProviderConnectionString = baseConnectionString;
    entityBuilder.Metadata = @"res://*/";

    return entityBuilder.ToString();
于 2011-11-16T19:23:00.007 回答