【问题标题】:connection string issue after hosting website托管网站后的连接字符串问题
【发布时间】:2012-07-01 03:32:06
【问题描述】:

请帮帮我! 我把我的网站放在 somee.com 上,他们给了这个连接字符串

Connection string:  workstation id=GWAPDataBase.mssql.somee.com;packet size=4096;user id=xxxx;pwd=xxxxx;data source=GWAPDataBase.mssql.somee.com;persist security info=False;initial catalog=GWAPDataBase

当我在本地主机上时我自动生成的连接字符串是

<add name="ApplicationServices" connectionString="data source=.\SQLEXPRESS;Integrated Security=SSPI;AttachDBFilename=|DataDirectory|\aspnetdb.mdf;User Instance=true" providerName="System.Data.SqlClient" />
<add name="GWAP_Entities" connectionString="metadata=res://*/App_Code.GWAPModel.csdl|res://*/App_Code.GWAPModel.ssdl|res://*/App_Code.GWAPModel.msl;provider=System.Data.SqlClient;provider connection string=&quot;data source=.\SQLEXPRESS;attachdbfilename=|DataDirectory|\aspnetdb.mdf;integrated security=True;user instance=True;multipleactiveresultsets=True;App=EntityFramework&quot;" providerName="System.Data.EntityClient" />

我试图修改它,但我收到一个错误提示

指定的命名连接在 配置,不打算与 EntityClient 提供程序一起使用, 或无效。

描述:执行过程中发生了未处理的异常 当前的网络请求。请查看堆栈跟踪以获取更多信息 有关错误的信息以及它在代码中的来源。

异常详细信息:System.ArgumentException:指定的命名 在配置中找不到连接,不打算 与 EntityClient 提供程序一起使用,或者无效。

来源错误:

第 19 行:#region 构造函数第 20 行:第 21 行:公共 GWAP_Entities() 第 22 行: : base(ConnectionString, ContainerName) 第 23 行:{

请帮助我应该如何修改连接字符串?

【问题讨论】:

  • 您可能不希望提供您的数据库框的域、用户名和密码。只是说。
  • 仅供参考:确保这些不是您的实际用户名和连接字符串的密码。
  • 更改您的密码现在
  • 感谢您的建议,但谁能帮助我,我非常需要这个
  • 产生错误的连接字符串是什么样的?

标签: asp.net sql entity-framework web hosting


【解决方案1】:

听起来您的连接字符串名称和实体框架期望的名称不匹配。如果没有有关代码外观的更多信息,我假设您使用 Visual Studio 中的向导从数据库生成模型。当您这样做时,您输入连接字符串的名称,然后将其硬编码在您的设计器文件中。一个例子:

public FooEntity() : base("name=FooEntity", "FooEntity")
{
    this.ContextOptions.LazyLoadingEnabled = true;
    OnContextCreated();
}

在这种情况下,字符串“FooEntity”需要是连接字符串的名称。如果它们不同,将找不到连接字符串。确保这些值匹配。

【讨论】:

  • 他们匹配,我现在试着把连接字符串像这样: 但也没有字
  • 你能把你的设计器文件的构造方法的代码贴出来吗?
  • 公共常量字符串 ConnectionString = "name=GWAP_Entities";公共常量字符串 ContainerName = "GWAP_Entities";公共 GWAP_Entities() : base(ConnectionString, ContainerName) { this.ContextOptions.LazyLoadingEnabled = true; } 公共 GWAP_Entities(string connectionString) : base(connectionString, ContainerName) { this.ContextOptions.LazyLoadingEnabled = true; } 公共 GWAP_Entities(EntityConnection 连接) : base(connection, ContainerName) { this.ContextOptions.LazyLoadingEnabled = true; }
猜你喜欢
  • 2016-05-25
  • 1970-01-01
  • 1970-01-01
  • 2011-06-25
  • 2018-01-01
  • 2014-03-08
  • 2012-01-23
  • 1970-01-01
相关资源
最近更新 更多