Archived Support Site

This support site is archived. You can view the old support discussions but you cannot post new discussions.

Using Sequelizer

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 when the application is deployed. 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 an alias is specified. Note that the connectionstring is NOT inserted into the connectionstring element if no alias is specified. If the the alias is specified, the name attribute of the inserted connectionstring element is the value of the alias you specify. Also note that connectionstrings are only replaced once your code is deployed, not when it's built.

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 and don't want to use the method below). 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;

Connectionstring Name

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. This will allow you to use a connection string for your local database connection when running the application on your own machine, and we'll make sure you're running with the right connection string when the application is deployed on AppHarbor.

Note that AppHarbor only replaces the connectionstring, a new one will not be inserted. If you want AppHarbor to replace the connectionString you have to define one with the relevant name in your application's configuration files.

Example:

<connectionStrings>
    <add name="connectionstringname" connectionString="Server=localhost;
        Database=my-app-debug;User ID=test;Password=dfy5fgFdsvV;" />
<connectionStrings>

In this case the entire connectionString value will be set to the value you can see on your database page on AppHarbor if the connection string name is "connectionstringname". DON'T use SQLSERVER_CONNECTION_STRING as the alias-name - due to the way we replace the values in the config file, this name will not work.

go_to_sql_server.png

edit_sequelizer_alias2.png

Entity Framework

The sequelizer add-on can generate connectionstrings valid for vintage (non-Code-First) Entity Framework. You must provide the metadata-string needed to generate the connectionstring valid for your model (i.e. something like res://*/DB.csdl|res://*/DB.ssdl|res://*/DB.msl). As with the connectionstring name, this is done on the Sequelizer add-on page (follow the "Go to ..." link on the application overview). We provide an example project demonstrating how to successfully use connectionstring replacement with Entity Framework and metadata.

Multiple Active Result Sets

You can enable Multiple Active Result Sets.aspx) for your Microsoft SQL Server connection strings on the Sequelizer admin page for your application.

** Initilializing database **

There are various ways you can initialize your database. Most good Object Relational Mappers will do this for you (we have an example showing how to do automatic migrations using Entity Framework). You can also use the "Generate Scripts" wizard in Management Studio or bulkcopy tool we provide.