【问题标题】:Cannot connect to SQL server AppHarbor无法连接到 SQL Server AppHarbor
【发布时间】:2013-03-15 18:59:26
【问题描述】:
 <entityFramework>
    <defaultConnectionFactory  type="System.Data.Entity.Infrastructure.LocalDbConnectionFactory, EntityFramework">
      <parameters>
        <parameter value="v11.0" />
      </parameters>
    </defaultConnectionFactory>
  </entityFramework>

以上相关吗?我只是把它放在那里,以免进一步搞砸。 但下面是我感兴趣的,是我本地sql server的连接字符串

  <connectionStrings>
    <add name="ApplicationServices" connectionString="Data Source=localhost;Initial Catalog=TestDB;User ID=lews;Password='therin'" providerName="System.Data.SqlClient" />

“当您在 Sequelizer 上创建数据库时,您可以指定连接字符串别名。这是在 Sequelizer 附加页面上完成的(按照应用程序概览中的“转到...”链接)。如果您在配置文件中将此名称设置为连接字符串的名称,我们会在部署代码时自动将其替换为您的 Sequelizer 连接字符串。”

这是 Appharbor 文档中的一个 sn-p。所以我假设 AppHarbor 会自动将数据源、初始目录、用户 ID 和密码替换为正确的值。但是由于某种原因无法连接。

下面是我这次与 MySQL 一起使用的另一个字符串,我再次假设 AppHarbor 应该自动注入正确的值,但它给出的错误是:

“在应用程序配置文件中找不到 PeopleEntities” 到底是怎么回事?

 <add name="PeopleEntities" connectionString="metadata=res://*/Context.People.csdl|res://*/Context.People.ssdl|res://*/Context.People.msl;provider=MySql.Data.MySqlClient;provider connection string=&quot;server=localhost;user id=root;database=people&quot;" providerName="System.Data.EntityClient" />
      </connectionStrings>

顺便说一句,名称“PeopleEntities”和“ApplicationServices”在 AppHarbor 上用作别名。 而且我不知道如何使用文档中给出的代码,数据库不是我的事。我如何同时使用本地和远程连接字符串?我在代码的哪里构建字符串并注入它?每当我创建 DBContext 实例时都必须这样做吗?等等。

任何想法都会很棒,谢谢!

编辑: 顺便说一句,如果我在 app.config 中硬编码连接字符串并使用 wcftestclient,它可以工作,它会查询数据库。但这不是一个好主意,显然连接字符串可以在没有警告的情况下更改。

无论如何,如果我使用硬编码的字符串部署它并使用我的站点连接到数据库.. 它不会查询 SQL 服务器.. 真的很困惑:(

【问题讨论】:

    标签: mysql sql-server connection-string appharbor


    【解决方案1】:

    http://support.appharbor.com/discussions/problems/2687-solved-mysql-provider-with-entity-framework-problem 对于实体框架: 这段标记非常重要:

     <system.data>
              <DbProviderFactories>
                <clear />
                <add name="MySQL Data Provider" invariant="MySql.Data.MySqlClient"
                description=".Net Framework Data Provider for MySQL"
                type="MySql.Data.MySqlClient.MySqlClientFactory, MySql.Data, 
                Version=6.4.4.0, Culture=neutral, PublicKeyToken=c5687fc88969c44d" />
              </DbProviderFactories>
            </system.data>
    

    请确保 MySQL 连接器组件是本地的。它也应该在您的 web.config 文件中,以确保将其放在 WCF 的 App.config 中。在连接字符串中使用相同的插件别名。

    对于 SQL Server 插件: 您需要在 web.config 中使用此标记:

    <system.web>
        <compilation debug="true" targetFramework="4.5" />
        <httpRuntime targetFramework="4.5"/>
         <membership>
          <providers>
            <clear />
            <add name="AspNetSqlMembershipProvider" type="System.Web.Security.SqlMembershipProvider" connectionStringName="ApplicationServices" enablePasswordRetrieval="false" enablePasswordReset="true" requiresQuestionAndAnswer="false" requiresUniqueEmail="false" maxInvalidPasswordAttempts="5" minRequiredPasswordLength="6" minRequiredNonalphanumericCharacters="0" passwordAttemptWindow="10" applicationName="/" />
          </providers>
        </membership>
        <profile>
          <providers>
            <clear />
            <add name="AspNetSqlProfileProvider" type="System.Web.Profile.SqlProfileProvider" connectionStringName="ApplicationServices" applicationName="/" />
          </providers>
        </profile>
        <roleManager enabled="true">
          <providers>
            <clear />
            <add connectionStringName="ApplicationServices" applicationName="/" name="AspNetSqlRoleProvider" type="System.Web.Security.SqlRoleProvider" />
            <add applicationName="/" name="AspNetWindowsTokenRoleProvider" type="System.Web.Security.WindowsTokenRoleProvider" />
          </providers>
        </roleManager>
      </system.web>
    

    你应该很高兴..

    【讨论】:

      猜你喜欢
      • 2016-02-26
      • 1970-01-01
      • 2021-06-05
      • 1970-01-01
      • 2010-10-26
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多