SuRaj Creator
SuRaj Creator

Reputation: 995

unable to Connect ASP.NET web page with mysql

I have used mysql for my web application in asp.net . However while running it in browser it shows me this error.

System.TimeoutException: Unable to read data from the transport connection: A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond. ---> 
System.IO.IOException: Unable to read data from the transport connection: A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond. --->
System.Net.Sockets.SocketException: A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond at System.Net.Sockets.Socket.Receive(Byte[] buffer, Int32 offset, Int32 size, SocketFlags socketFlags) at 
System.Net.Sockets.NetworkStream.Read(Byte[] buffer, Int32 offset, Int32 size) --- End of inner exception stack trace --- at
System.Net.Sockets.NetworkStream.Read(Byte[] buffer, Int32 offset, Int32 size) at MySql.Data.Common.MyNetworkStream.Read(Byte[] buffer, Int32 offset, Int32 count) --- End of inner exception stack trace --- at 
MySql.Data.Common.MyNetworkStream.Read(Byte[] buffer, Int32 offset, Int32 count) at 
MySql.Data.MySqlClient.TimedStream.Read(Byte[] buffer, Int32 offset, Int32 count) at 
System.IO.BufferedStream.Read(Byte[] array, Int32 offset, Int32 count) at MySql.Data.MySqlClient.MySqlStream.ReadFully(Stream stream, Byte[] buffer, Int32 offset, Int32 count) at 
MySql.Data.MySqlClient.MySqlStream.LoadPacket() at MySql.Data.MySqlClient.MySqlStream.ReadPacket() at MySql.Data.MySqlClient.NativeDriver.Open() at MySql.Data.MySqlClient.Driver.Open() at MySql.Data.MySqlClient.Driver.Create(MySqlConnectionStringBuilder settings) at MySql.Data.MySqlClient.MySqlPool.CreateNewPooledConnection() at MySql.Data.MySqlClient.MySqlPool.GetPooledConnection() at MySql.Data.MySqlClient.MySqlPool.TryToGetDriver() at MySql.Data.MySqlClient.MySqlPool.GetConnection() at MySql.Data.MySqlClient.MySqlConnection.Open() at System.Data.Common.DbDataAdapter.FillInternal(DataSet dataset, DataTable[] datatables, Int32 startRecord, Int32 maxRecords, String srcTable, IDbCommand command, CommandBehavior behavior) at 
System.Data.Common.DbDataAdapter.Fill(DataTable[] dataTables, Int32 startRecord, Int32 maxRecords, IDbCommand command, CommandBehavior behavior) at System.Data.Common.DbDataAdapter.Fill(DataTable dataTable) at 
school.Page_Load(Object sender, EventArgs e) in 
E:\VIDYAN\school.aspx.vb:line 20

Connection String

<add name="constr" connectionString="Data Source=localhost;port=81;Initial Catalog=Vidyan;User Id=root;password="/>

VB code

Imports System.Data
Imports System.Configuration
Imports MySql.Data.MySqlClient
Partial Class school
    Inherits System.Web.UI.Page

    Dim constr As String = ConfigurationManager.ConnectionStrings("constr").ConnectionString
    Dim query, str As String

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        Try
            ViewState("Data") = ""
            Using con As New MySqlConnection(constr)
                Using cmd As New MySqlCommand("SELECT * FROM school")
                    Using sda As New MySqlDataAdapter()
                        cmd.Connection = con
                        sda.SelectCommand = cmd
                        Using dt As New DataTable()
                            sda.Fill(dt)
                            ViewState("Data") = dt
                            schoollists.DataSource = dt
                            schoollists.DataBind()

                        End Using
                    End Using
                End Using
            End Using

        Catch ex As Exception
            Response.Write(ex)
        End Try
    End Sub

    Protected Sub DataPager1_PreRender(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.PreRender
        Try
            Dim table As DataTable = ViewState("Data")
            schoollists.DataSource = table
            schoollists.DataBind()

        Catch ex As Exception
            'Response.Write(ex)
        End Try

    End Sub
End Class

Upvotes: 0

Views: 450

Answers (1)

Neo
Neo

Reputation: 2405

The default port for MySQL is 3306, in your connection string it is 81, I'd check the port for WAMP and try 3306 :)

Upvotes: 1

Related Questions