Click here to Skip to main content
15,910,981 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Dear All,

I am developing an asp.net application, and using mysql workbench as database.
I've uploaded my database to the server(Cpanel), trying to connect and at the time of connection.Open(), it throws the following exception, Please help me. I am a newbee
My Code:

VB
Dim connection As New MySqlConnection
            connection.ConnectionString = Server="IP of My CPANEL"; Port = portNumber; Database=xxxxx; Uid=<username>; Pwd=<password>;


VB
Dim adap As New MySqlDataAdapter("SELECT * FROM reg_employs WHERE EmpID = '" & TextBoxID.Text.Trim & "' AND EmpPass = md5('" & TextBoxPass.Text.Trim & "')", connection)
           Dim dt As New DataTable()
           adap.Fill(dt)
           If dt.Rows.Count > 0 Then
               Session("EmpID") = dt.Rows(0).Item("EmpID").ToString
               Server.Transfer("Main.aspx", True)
           Else
               Label1.Text = "Invalid Credentials, Please Try again"
           End If



MySql.Data.MySqlClient.MySqlException was caught
  ErrorCode=-2147467259
  HResult=-2147467259
  Message=Reading from the stream has failed.
  Number=0
  Source=MySql.Data
  StackTrace:
       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 ERP.Login.ButtonLogin_Click(Object sender, EventArgs e) in D:\Srinivas\Dot Net\ASP\vs2010\ERP\ERP\Login.aspx.vb:line 13
  InnerException: System.IO.EndOfStreamException
       HResult=-2147024858
       Message=Attempted to read past the end of the stream.
       Source=MySql.Data
       StackTrace:
            at MySql.Data.MySqlClient.MySqlStream.ReadFully(Stream stream, Byte[] buffer, Int32 offset, Int32 count)
            at MySql.Data.MySqlClient.MySqlStream.LoadPacket()
       InnerException:
Posted
Updated 21-Jan-19 11:23am
v4
Comments
Afzaal Ahmad Zeeshan 1-Apr-15 4:46am    
Never share your password or username on Internet.
CHill60 1-Apr-15 4:53am    
Don't concatenate strings to build your sql statement - use parameterized queries to avoid SQL Injection[^]
Don't put your logon and password out onto public sites.
Your connection string does not look correct.
This looks similar to a bug in some versions of MySQL - check you have the latest version and any patches.
It may be that the connection has timed out - try checking for the open connection before running the query
Richard MacCutchan 21-Jan-19 11:15am    
What is the exact content of the connection string when you run the app? What you have shown above will not even compile.

1 solution

VB
Dim adap As New MySqlDataAdapter("SELECT * FROM reg_employs WHERE EmpID = '" & TextBoxID.Text.Trim & "' AND EmpPass = md5('" & TextBoxPass.Text.Trim & "')", connection)

Not necessary a solution to your question, but another problem you have.
Never build an SQL query by concatenating strings. Sooner or later, you will do it with user inputs, and this opens door to a vulnerability named "SQL injection", it is dangerous for your database and error prone.
A single quote in a name and your program crash. If a user input a name like "Brian O'Conner" can crash your app, it is an SQL injection vulnerability, and the crash is the least of the problems, a malicious user input and it is promoted to SQL commands with all credentials.
SQL injection - Wikipedia[^]
SQL Injection[^]
SQL Injection Attacks by Example[^]
PHP: SQL Injection - Manual[^]
SQL Injection Prevention Cheat Sheet - OWASP[^]
How can I explain SQL injection without technical jargon? - Information Security Stack Exchange[^]
 
Share this answer
 
Comments
Richard Deeming 22-Jan-19 8:26am    
A good point. But given it's approaching four years since the question was posted, that database has almost certainly been destroyed by now. :)

(Question was resurrected by solution #1, posted yesterday, and since removed.)
Patrice T 22-Jan-19 9:13am    
Oops

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900