Connect ASP.NET to database

Use the following code to connect to an Access database without a DSN / ODBC. Replace the database name (db1.mdb) to the name that your database has.

If you want to connect ASP.NET to MySQL you use the following code (which uses Connector.Net). Replace the login details against those that you have received from us.

We are currently using version 5.2 of MySql.Data.dll. If you are using precompiled code needs to be compiled against this version.

You can also use the ODBC (via MyODBC), as illustrated by the following code. Replace the login details against those that you have received from us.

The code samples are currently only available in Swedish

The new .NET-platform

Connection strings for connections to MySQL from the new .NET platform.

private string mysql_host = ”mysqlxxx.loopia.se”;
private string mysql_user =d”user@xxxxx”;
private string mysql_password = ”lösenord”;
private string mysql_database = ”databasnamn”;

ODBC:

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:

string strConn = "server=" + mysql_host + ";uid=" + mysql_user + ";pwd=" + mysql_password + ";database=" + mysql_database + ";";

We got version 6.6.4 of MySql.Data.dll installed. If you use precompiled code then it need to be compatible with this version.

 

Was this article helpful?

Related Articles