Create contact with the MySQL database in the localhost
Posted by: Gunnar Feltborg
Date: February 27, 2014 08:45AM

Have just started to learn to use MySQL instead of Access. Have begun with a simple test program that I must record three input data to the database (MySQL).
I have OS: Windows 7 (64bit), Web Development: ASP.NET Framework 4.5 (VB).
I have added the file MySql.Data.dll v.6.6.5 folder Bin.

The following is in MySQL Workbench under the Manage Server Connections:
Hostname: localhost
Port: 3307
Username: root
When I press the 'Test Connection' I get the following message:
Connected to MySQL at localhost:3307 with user root. Connection parameters are correct.
Is this a confirmation that the contact with the database is OK or it says something else?

I have the following aspx file:

<%@ Page Language="vb" Debug="true" %>
<%@ Import Namespace="System.Data" %>
<%@ Import Namespace="System.Data.Odbc" %>
<%@ Import Namespace="MySql.Data.MySqlClient" %>

<script runat="server">



Sub Button1_Click(sender As Object, e As EventArgs)
Dim mysql_password As String = "QWER1234"
Dim mysql_host As String = "localhost"
Dim mysql_user As String = "root"
Dim mysql_database As String = "test"

Dim strConn As String = "SERVER=" & mysql_host & "" & _
"PORT=3307" & _
"DATABASE=" & mysql_database & "" & _
"UID=" & mysql_user & "" & _
"PWD=" & mysql_password & ""

Dim sql As String = "INSERT INTO data1(namn,postort,telefon) VALUES('" & txtNamn.Text & "','" & txtPostort.Text & "','" & txtTelefon.Text & "')"
Dim conn As New MySql.Data.MySqlClient.MySqlConnection(strConn)
Dim Cmd As New MySql.Data.MySqlClient.MySqlCommand(sql, conn)
Dim objDR As MySql.Data.MySqlClient.MySqlDataReader
conn.Open()
objDR = Cmd.ExecuteReader(System.Data.CommandBehavior.CloseConnection)
conn.Close()

End Sub

</script>

When I run this I get the following error message:
Unable to connect to any of the specified MySQL hosts.

I have tested with different server name but it gets the same error .... no contact!

Is there anyone who can help me as MySQL beginners to solve this problem?



Enclosed is my web.config:
<?xml version="1.0"?>
<configuration>
<appSettings/>
<connectionStrings/>
<system.web>
<customErrors mode="Off"/>
<compilation debug="true" targetFramework="4.5">
<assemblies>
<add assembly="System.Web.DataVisualization, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
<add assembly="System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089"/>
<add assembly="System.Design, Version=4.0.0.0, Culture=neutral, PublicKeyToken=B03F5F7F11D50A3A"/>
<add assembly="System.Web.Extensions.Design, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
<add assembly="*"/>
</assemblies>
</compilation>
<pages controlRenderingCompatibilityVersion="3.5" clientIDMode="AutoID">
<namespaces>
<add namespace="System.Web.UI.DataVisualization.Charting"/>
</namespaces>
</pages>

</system.web>

</configuration>

Options: ReplyQuote


Subject
Written By
Posted
Create contact with the MySQL database in the localhost
February 27, 2014 08:45AM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.