trying to connect to remote mysql from .asp page

2019-03-01 01:05发布

问题:

I am trying to connect to a remote MySQL database from Classic ASP page, when I write VBScript code in it the website is giving HTTP 500 Internal Server Error. I checked with the host they are saying its not an error from their end.

Please help me.

<%
dim myConnection
dim connectString

username = "bla"
password = "bla"
database = "bla"
host = "bla"

Set myConnection = Server.CreateObject("ADODB.Connection")
Set RSTitleList = Server.CreateObject("ADODB.Recordset")

connectString = "DRIVER={MySQL ODBC 3.51 Driver}; SERVER="&host&"; DATABASE="&database&"; UID="&username&";PASSWORD="&password&"; OPTION=3"

**myConnection.Open connectString   ---- HERE I'M GETTING ERROR. ABOVE CODE IS WORKING FINE.**

Set RSTitleList =  myConnection.Execute( "Select * From questions") %>


<!-- Begin our column header row -->  

<!-- Ok, let's get our data now -->
<% do while not RStitleList.EOF %>   
   <p>           <%=RStitleList("id")%>).

             <b><%=RSTitleList("question") %></b>  &nbsp&nbsp&nbsp&nbsp <%=RSTitleList("answer") %> <!--<a href="emailaddress.htm">-->More&#9658;<!--</a>--> <br>
             <p>&nbsp&nbsp&nbsp&nbsp <font color="purple"> answered by </font> <b>Sadhu</b> on 1-10-2015 </p>   
    </p>


   <% RSTitleList.MoveNext%>

<%loop %>

回答1:

OK, you've found the underlying error message (on the server). Thank you. It's important:

 [MySQL][ODBC 3.51 Driver]Access denied for user 'bla'@'162.253.126.112' (using password: YES) 

Since you're getting "access denied", and since a MySQL identity" is a combination of username + host, this means one of three things:

  1. You're passing mySQL the wrong username...

  2. ... And/or you're logging in from a host that hasn't been granted access...

  3. ... And/or you're passing mySql the wrong password

Normally, the best way to troubleshoot would be with the mysql command-line client. I'm guessing this is probably not an option for you.

Another way might be Control Panel > ODBC > Test Connection:

  • Simplest Way to Test ODBC on WIndows

But this might not an option either, if your IIS webserver and MySQL database are co-located on the remote server (instead of local).

Here are some other suggestions for troubleshooting your mySQL username/password:

  • MySQL ERROR 1045 (28000): Access denied for user 'bill'@'localhost' (using password: YES)

  • MySQL - ERROR 1045 - Access denied

  • 1045 access denied for user - MySQL error

  • You can also work with your hosting provider to verify the combination username + host(s) + password you're using to authenticate to mySql.