Connecting ASP.NET to a database on Loopia hosting can be done against either an Access (.mdb) database or a MySQL database. For MySQL, you can either use MySQL Connector/NET (the native ADO.NET provider) or ODBC (Open Database Connectivity) via MyODBC. This article lists the supported connection methods and provides connection string examples for our current .NET platform.
Connecting ASP.NET to an Access database
Use the following code sample to connect to an Access database without a DSN (Data Source Name) / ODBC. Replace the database name (db1.mdb) with the name of your own database.
Connecting ASP.NET to MySQL with Connector/NET
If you want to connect ASP.NET to MySQL, use the following code sample, which uses MySQL Connector/NET. Replace the login details with those you have received from us.
We are currently using version 5.2 of MySql.Data.dll. Precompiled code must be compiled against this version.
Connecting ASP.NET to MySQL with ODBC
You can also connect via ODBC (using MyODBC), as illustrated by the following code sample. Replace the login details with those you have received from us.
The code samples are currently only available in Swedish.
The new .NET platform
Connection strings for connecting to MySQL from the new .NET platform are shown below. Define your connection variables first:
private string mysql_host = "mysqlxxx.loopia.se"; private string mysql_user = "user@xxxxx"; private string mysql_password = "password"; private string mysql_database = "database_name";
ODBC connection string
string strConn = "DRIVER={MySQL ODBC 5.2w Driver};SERVER=" + mysql_host + ";PORT=3306;DATABASE=" + mysql_database + ";UID=" + mysql_user + ";PWD=" + mysql_password + ";OPTION=3";
Connector/NET connection string
string strConn = "server=" + mysql_host + ";uid=" + mysql_user + ";pwd=" + mysql_password + ";database=" + mysql_database + ";";
On the new platform we have version 6.6.4 of MySql.Data.dll installed. Precompiled code must be compatible with this version.