0

I want to use a database on my asp.net website, but i have some problems with connecting to my host. I use the following code and i got an error:

private const string ConnStr = "Provider=MSDASQL; Driver={MySQL ODBC 5.1 Driver};Server=pdb9.xxx.net;Database=xxx;User=xxx;Password=xxx;Option=3;";    
using(OdbcConnection con = new OdbcConnection(ConnStr))
using(OdbcCommand cmd = new OdbcCommand("INSERT INTO sample(name, address) VALUES (?,?)", con))
{
    cmd.Parameters.Add("@name", OdbcType.VarChar, 255).Value = TextBox3.Text.Trim();
    cmd. Parameters.Add("@address", OdbcType.VarChar, 255).Value = TextBox4.Text.Trim();

    con.Open();
    cmd.ExecuteNonQuery();
    BindDataGrid();
}

The error appears when i call con.open();

ERROR [IM002] [Microsoft][ODBC Driver Manager] Data source name not found and no default driver specified

I always used the MySQL database on my PHP pages and it worked fine. Besides Mysql my host also supports PostgreSQL. Does someone know how i can solve this problem or how to find a solution using a database on an asp.net page?

1
  • are you using 64bit windows? Commented May 3, 2014 at 14:32

2 Answers 2

1

Here is how commonly MySql connection string look like in config file:

<add name="name" connectionString="server=IP;user id=USERNAME;password=PASSWORD;database=DATABASE;persist security info=True" providerName="MySql.Data.MySqlClient"/>

in code:

vat connectionString = "server=IP;user id=USERNAME;password=PASSWORD;database=DATABASE;persist security info=True"

And i suggest you to use MySql Connector For .NET, you can install it using NuGET or from official site

Sign up to request clarification or add additional context in comments.

Comments

0

ConnectionString syntax is like

connectionString="DRIVER={MySQL ODBC 3.51 Driver};Database=YourDatabase;Server=localhost;UID=YourUsername;PWD=YourPassword;"

1 Comment

This is the connection string i tried before, but i got the some error.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.