By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,851 Members | 1,121 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,851 IT Pros & Developers. It's quick & easy.

Can't connect to localhost using odbc string connections

P: 2
Hello,

Here's my problem. I cannot connect to mysql database using odbc string
connections or dns. I keep getting a "cannot connect to mysql server localhost." I'm running windows XP Pro and have installed IIS as my server. I have installed Mysql 5.0 and mysql ODBC driver 3.51.12 in their default locations. Database is up and running okay, as I've been able to create databases and tables and access
them via the command prompt and mysql administrator. I have also successfully created and tested odbc link to these databases in odbc data source administrator.

I'm fairly new to this so I'm going to include the script I've been trying to use.
Maybe it's just my syntax. I'm trying to do this in ASP, and there are two things I 'm unsure of. The first one being the server parameter. Is localhost correct? Also, I am unsure if I have to include the complete path for the database parameter, and it's so where is the actual file that I need to point to?
I have searched relentlessly for a solution to this problem and I'm about ready to
throw in the towel. Any help would be greatly appreciated.

Thank you very much,
Mike
Expand|Select|Wrap|Line Numbers
  1. <% 
  2. 'declare the variables 
  3. Dim Connection
  4. Dim ConnString
  5. Dim Recordset
  6. Dim SQL
  7.  
  8. 'declare the SQL statement that will query the database
  9. SQL="SELECT *tablename"
  10.  
  11. 'define the connection string, specify database driver
  12. ConnString="DRIVER={MySQL ODBC 3.51 Driver}; SERVER=localhost;"
  13. "DATABASE=C:\Program Files\MySQL\MySQL Server 5.0\data\database folder name;" &_
  14. "UID=root;PASSWORD=password; OPTION=3"
  15.  
  16. 'create an instance of the ADO connection and recordset objects
  17. Set Connection=Server.CreateObject("ADODB.Connection")
  18. Set Recordset=Server.CreateObject("ADODB.Recordset")
  19.  
  20. 'Open the connection to the database
  21. Connection.Open ConnString
  22.  
  23. 'Open the recordset object executing the SQL statement and return records 
  24. Recordset.Open SQL,Connection
  25.  
  26. 'first of all determine whether there are any records 
  27. If Recordset.EOF Then 
  28. Response.Write("No records returned.") 
  29. Else 
  30. 'if there are records then loop through the fields 
  31. Do While NOT Recordset.Eof   
  32. Response.write Recordset("user_id")
  33. Response.write Recordset("last_name")
  34. Response.write Recordset("first_name")
  35. Response.write "<br>"    
  36. Recordset.MoveNext     
  37. Loop
  38. End If
  39.  
  40. 'close the connection and recordset objects freeing up resources
  41. Recordset.Close
  42. Set Recordset=nothing
  43. Connection.Close
  44. Set Connection=nothing
  45. %>
Oct 25 '06 #1
Share this Question
Share on Google+
2 Replies


P: 7
Try giving just the database name; why give absolute dir path?

Next time read the Posting Guidelines before you post in this forum and enclose your code within PHP or CODE tags!! - Ronald :cool:

Hello,

Here's my problem. I cannot connect to mysql database using odbc string
connections or dns. I keep getting a "cannot connect to mysql server localhost." I'm running windows XP Pro and have installed IIS as my server. I have installed Mysql 5.0 and mysql ODBC driver 3.51.12 in their default locations. Database is up and running okay, as I've been able to create databases and tables and access
them via the command prompt and mysql administrator. I have also successfully created and tested odbc link to these databases in odbc data source administrator.

I'm fairly new to this so I'm going to include the script I've been trying to use.
Maybe it's just my syntax. I'm trying to do this in ASP, and there are two things I 'm unsure of. The first one being the server parameter. Is localhost correct? Also, I am unsure if I have to include the complete path for the database parameter, and it's so where is the actual file that I need to point to?
I have searched relentlessly for a solution to this problem and I'm about ready to
throw in the towel. Any help would be greatly appreciated.

Thank you very much,
Mike
Expand|Select|Wrap|Line Numbers
  1. <% 
  2. 'declare the variables 
  3. Dim Connection
  4. Dim ConnString
  5. Dim Recordset
  6. Dim SQL
  7.  
  8. 'declare the SQL statement that will query the database
  9. SQL="SELECT *tablename"
  10.  
  11. 'define the connection string, specify database driver
  12. ConnString="DRIVER={MySQL ODBC 3.51 Driver}; SERVER=localhost;"
  13. "DATABASE=C:\Program Files\MySQL\MySQL Server 5.0\data\database folder name;" &_
  14. "UID=root;PASSWORD=password; OPTION=3"
  15.  
  16. 'create an instance of the ADO connection and recordset objects
  17. Set Connection=Server.CreateObject("ADODB.Connection")
  18. Set Recordset=Server.CreateObject("ADODB.Recordset")
  19.  
  20. 'Open the connection to the database
  21. Connection.Open ConnString
  22.  
  23. 'Open the recordset object executing the SQL statement and return records 
  24. Recordset.Open SQL,Connection
  25.  
  26. 'first of all determine whether there are any records 
  27. If Recordset.EOF Then 
  28. Response.Write("No records returned.") 
  29. Else 
  30. 'if there are records then loop through the fields 
  31. Do While NOT Recordset.Eof   
  32. Response.write Recordset("user_id")
  33. Response.write Recordset("last_name")
  34. Response.write Recordset("first_name")
  35. Response.write "<br>"    
  36. Recordset.MoveNext     
  37. Loop
  38. End If
  39.  
  40. 'close the connection and recordset objects freeing up resources
  41. Recordset.Close
  42. Set Recordset=nothing
  43. Connection.Close
  44. Set Connection=nothing
  45. %>
Nov 1 '06 #2

P: 2
Try giving just the database name; why give absolute dir path?

yep, finally figured that one out. Also, after a long end and painstaking search I finally ran across an article that talked about com objects. This jogged my memory and I realized the very first time I tried to run this script(with the correct database name, no path) my firewall alerted me to the possibility of a Trojan, so I blocked all access to my own script. Pretty funny huh? If I hadn't run across that one article, I might still be pulling my hair out.

Thanks for replying,
I'm sure I'll be needing to talk with all of you again soon,
mike
Nov 2 '06 #3

Post your reply

Sign in to post your reply or Sign up for a free account.