Link to home
Start Free TrialLog in
Avatar of bschave2
bschave2

asked on

how to get connection string on aspx page from web.config file using mysql odbc driver?

settings in web.config
<connectionStrings>
    <add name="Connection" connectionString="Driver={MySQL ODBC 3.51 Driver};datasource=mySQL;database=;uid=;password=" providerName ="System.Data.Odbc"/>
   </connectionStrings>

Code in aspx.cs page to connect to web.config connection string
 string ConnStr = System.Configuration.ConfigurationManager.ConnectionStrings["Connection"].ToString() ;

I am getting this error message
ERROR [HY000] [MySQL][ODBC 3.51 Driver]Can't connect to MySQL server on 'localhost' (10061)
ERROR [HY000] [MySQL][ODBC 3.51 Driver]Can't connect to MySQL

help is greatly appreciated!
Avatar of silemone
silemone
Flag of United States of America image

Here is a great site:  http://www.connectionstrings.com/

Pick the server you're using...most likely Sql Server 2005 and see how all the connect strings are built...
are you using a mySql DB?
Avatar of bschave2
bschave2

ASKER

yes, mysql driver to get to mysql db. the link above is for connection strings only. I have the connection string, but noo way to connect to the string on my asp page.
found someone with a same problem:

"I discovered that the cause of the problem was my using ODBC driver instead of MySQL Connector; apparently my ISP does not support ODBC.  Also I was using

I rewrote the connection string in my web.config file and now my application works."

Regards,
right, but I need the code to reference the connection string on my pages.
ASKER CERTIFIED SOLUTION
Avatar of silemone
silemone
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
the string was incorrect. it didn't support the string from the web.config file. correct code is


  OdbcConnection con = new OdbcConnection(System.Configuration.ConfigurationManager.ConnectionStrings["Connection"].ToString());