简体   繁体   中英

Cannot connect to SQL server AppHarbor

 <entityFramework>
    <defaultConnectionFactory  type="System.Data.Entity.Infrastructure.LocalDbConnectionFactory, EntityFramework">
      <parameters>
        <parameter value="v11.0" />
      </parameters>
    </defaultConnectionFactory>
  </entityFramework>

Is the above relevant? I just have it in there in order not to screw things further. But below is what I'm interested in, it is a connection string of my local sql server

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

"When you create a database on Sequelizer you can specify a connection string alias. This is done on the Sequelizer add-on page (follow the "Go to ..." link on the application overview). If you set this name as the name of your connection string in your configuration file, we'll automatically replace it with your Sequelizer connection string when your code is deployed."

That's a snippet from Appharbor's documentation. So I assume that Data Source, Initial Catalog, User ID and password is automatically replaced with the correct values by AppHarbor. But it can't connect for some reason.

Below is another string I am using with MySQL this time, again I assume that AppHarbor should automagically inject the right values, but the error it gives is:

"PeopleEntities cannot be found in the application configuration file" What is going on?

 <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>

Btw, the names "PeopleEntities" and "ApplicationServices" are used as aliases on AppHarbor. And I have no idea how to use the code given in the documentation, databases is just not my thing.. how do I use both local and remote conn strings? Where in the code do I build the string and inject it? Do I have to do it whenever I create a DBContext instance? Etc..

Any ideas will be great, thanks!

EDIT: Btw, if I hard code the connection strings, in the app.config and use a wcftestclient, it works, it queries the database.. but this isn't a good idea, apparently the connection strings can change without warning.

Anyway if I deploy it with the strings hardcoded and connect to the database with my site.. it doesn't query the SQL server.. really confused :(

http://support.appharbor.com/discussions/problems/2687-solved-mysql-provider-with-entity-framework-problem For Entity Framework: This piece of markup is unbelievable important:

 <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>

Oh make sure the MySQL connector assemblies are local. And it should be in your web.config file as well, to be extra sure place it in your WCF's App.config. Use the same addon alias in your connection string.

For SQL Server addon: You need this markup in the 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>

And you should be good to go..

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM