• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 4071
  • Last Modified:

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!
0
bschave2
Asked:
bschave2
  • 4
  • 3
1 Solution
 
silemoneCommented:
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...
0
 
silemoneCommented:
are you using a mySql DB?
0
 
bschave2Author Commented:
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.
0
Cloud Class® Course: CompTIA Healthcare IT Tech

This course will help prep you to earn the CompTIA Healthcare IT Technician certification showing that you have the knowledge and skills needed to succeed in installing, managing, and troubleshooting IT systems in medical and clinical settings.

 
silemoneCommented:
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,
0
 
bschave2Author Commented:
right, but I need the code to reference the connection string on my pages.
0
 
silemoneCommented:
pls explain because that's what this does:

 string ConnStr = System.Configuration.ConfigurationManager.ConnectionStrings["Connection"].ToString() ;

Maybe you post more code...what do yo mean by 'I need the code to reference the connection string on my pages'
0
 
bschave2Author Commented:
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());
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Cloud Class® Course: Microsoft Office 2010

This course will introduce you to the interfaces and features of Microsoft Office 2010 Word, Excel, PowerPoint, Outlook, and Access. You will learn about the features that are shared between all products in the Office suite, as well as the new features that are product specific.

  • 4
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now