error to connect on remote mysql database - mysql

So, I´ve an application that comunicates with a remote mysql db, so its on hostinger and works properly for more de 2 years, and few days ago its just stop working, and the error happens when I try to open connection, the error its about it ↓
The handshake failed due to an unexpected packet format
but what i dont get is, I´ve tested the same connection on 2 different compannies, and on hostinger its doesnt work, but on another works fine....Im using vb.net and remote mysql on hostinger...
I´d like to know if someone could help me...
the code just to test open the connection is ↓
Dim conn As String = "Server=myserver-here;Port=3306;Database=u8424_test;Uid=u8424_teste;Pwd=Test2021"
Using cn = New MySqlConnection(conn)
Try
cn.Open()
MsgBox("SUCESS")
cn.Close()
MsgBox("CLOSING CONNECTION")
Catch ex As Exception
MsgBox("SOME ERROR..." & vbNewLine & ex.ToString)
End Try
End Using
since then, thanks for everyone!

so in my case, I got the solution, in fact the problem was on hostinger, that changed their configuration and now we´ve to put the param about ssl in the end of the connection string, something like this already works here for me↓
Dim conn As String = "Server=myserver-here;Database=u8424_test;Uid=u8424_teste;Pwd=Test2021;ssl mode=none;"
even if you dont use ssl, you must put something, but you have to pass this param or some of these list ↓
https://dev.mysql.com/doc/dev/connector-net/6.10/html/T_MySql_Data_MySqlClient_MySqlSslMode.htm

Related

ODBC connection string to Snowflake for Access Pass Thru Query

I am trying to create a connection string to get to Snowflake data from Access 2010 and above. I can create a database DSN and link to the tables I use, but I need to build DSN-less connection strings for distributed applications. Here's what I have so far, it fails with the message "ODBC connection to xxxx failed". Here's what I have so far:
ODBC;Driver={SnowflakeDSIIDriver}; Server=https://server name; Role=role name;Warehouse=warehouse name;Database=db name;Schema=schema name;UID=snowflake ID; PWD=snowflake password;
I think you are on the right track. I have the same thing and it works.
ODBC;
driver={SnowflakeDSIIDriver};
server=accountname.snowflakecomputing.com;database=dbname;
schema=public;
warehouse=whname;
role=rlname;
Uid=userid;
Pwd=password;
Very odd that the DSN one works and your doesn't.
I can confirm that DNS-free connections work fine in Access 2013. I have not tested on Access 2010, but I have it available if that needs testing.
The first problem I encountered is that the Snowflake ODBC driver reports 32/64-bit in the ODBC section of Control Panel, but it may not have one or the other installed.
In my case, it showed in the DSN sources as 32/64-bit, but I had only the 64-bit version installed. Notice that after installing the 32-bit driver, the Programs and Features (where to go normally for uninstalling apps) shows both the 64 and 32 bit drivers.
After installing the 32-bit driver, it was just a matter of getting the connection string right. You want to copy it from the URL on your Snowflake web UI. Strip off the https:// part, and then keep everything up to and including the snowflakecomputing.com in the url. That's what you'll use for the server.
Edit 2: I missed the part of the question that referenced pass through queries and was describing a procedure I tested recently for DNS-free connection using VBA. I tested the pass-through connection and it worked fine. The only difference is in the ODBC connection string you need to keep the "ODBC;" prefix:
ODBC;Driver{SnowflakeDSIIDriver};server=<your_URL_everything_before_snowflakecomputing.com>.snowflakecomputing.com;uid=greg;pwd=xxxxxx
Edit: One thing I forgot and am adding... The built-in Access data engine did not work for me to connect with a DNS-free connection. The code shows that it's using ActiveX Data Objects (ADO). You need to add a reference to that in your VBA project:
' For the account, use everything after https:// up to and including
' snowflakecomputing.com in your URL when connecting to Snowflake using the web UI.
Const SNOWFLAKE_ACCOUNT = "<your_account>.<your_region>.snowflakecomputing.com"
Const SNOWFLAKE_USER = "greg"
Const SNOWFLAKE_PASSWORD = "xxxxx"
Public Sub Main()
Dim odbc As String
Dim sfCon As ADODB.Connection
Set sfCon = OpenDatabaseConnection(GetConnectionString())
If Not sfCon Is Nothing Then
'Use the connection here...
sfCon.Close
End If
End Sub
Private Function GetConnectionString()
GetConnectionString = "Driver={SnowflakeDSIIDriver}" + _
";server=" + SNOWFLAKE_ACCOUNT + _
";uid=" + SNOWFLAKE_USER + _
";pwd=" + SNOWFLAKE_PASSWORD + _
";network_timeout=60" + _
"login_timeout=60"
End Function
Public Function OpenDatabaseConnection(ConnString As String) As ADODB.Connection
On Error GoTo Handler
Dim database As ADODB.Connection
Set database = New ADODB.Connection
With database
.ConnectionString = ConnString
.ConnectionTimeout = 60
.Open
End With
Set OpenDatabaseConnection = database
Exit Function
Handler:
MsgBox "Error: " + Err.Description
End Function

Connection Error using mysql in Visual Basic

I'm trying to setup connection to a database within my program, and I'm running into a problem when adding data to the Database. I know I've done something wrong but I can't for the life of me figure it out!
Basically the program throws an error at the ExecuteNonQuery() line, saying the connection is not open. But I've opened the connection just a couple of lines above? It might be because I'm trying to import the connection from a seperate form?
The Error is : An unhandled exception of type 'System.InvalidOperationException' occurred in MySql.Data.dll
Additional information: Connection must be valid and open.
I know some parts are commeneted out, thats just what I do whem I'm troubleshooting.
Imports MySql.Data.MySqlClient
Public Class frmCompanyAdd
Public Sub Button1_Click(sender As Object, e As EventArgs) Handles btnAdd.Click
'Try
frmMain.conn.Open()
' Catch ex As Exception
'End Try
Dim cmd As New MySqlCommand(String.Format("INSERT INTO `Company` (`companyname` , `location` , `contactphone` , `numberpc`) VALUES (" & txtcompanyname.Text & "," & txtPst.Text & " , " & txtPhone.Text & "," & txtPcNo.Text & ")"))
cmd.ExecuteNonQuery()
'frmMain.conn.Close()
End Sub
It looks like you never set the connection on the cmd command after you construct it. You either need to provide the connection in the constructor or set it afterwards.
As usual, I must also point out that your INSERT statement is open to a possible malicious SQL injection attack. You should use a parameterized query instead of concatenating values together to form your query.
I can't get the library installed, but it's probably just a constructor overload, e.g. Dim cmd As New MySqlCommand(yourProperlyParameterizedQuery, frmMain.conn)

ASP Error: Multiple-step operation generated errors. Check each status value. (Object Required)

My old website in ASP started generating this error:
Microsoft Cursor Engine error '80040e21'
Multiple-step operation generated errors. Check each status value.
I haven't changed recently anything - perhaps my hosting provider made a change but the error is pointing to this line of code:
rs.Open SQL, adoCon
I checked: rs, adoCon and SQL are all set and it used to work for years before.
Set rs = Server.CreateObject("ADODB.Recordset")
adoCon.Open "DRIVER={MySQL ODBC 3.51 Driver}; SERVER=<SERVER_NAME>; PORT=<PORT_NUMBER>;" &_
"DATABASE=<DBNAME>; USER=<USERNAME>; PASSWORD=<PASS>; OPTION=3;"
SQL is correct - I directly injected it into mySQL web interface and it generated needed results.
When I handle this error in ASP the Error.Description prints
"Object required"
What is it complaining about?
The answer to my question is that I had to convert decimal field to string. The fix looked like this:
SELECT Convert(Price,char) as Price FROM Table;
This is very strange but perhaps something was changed on my hosting provider site that caused this issue. I actually found similar solution here (strange mysql results in asp) which helped me to discover the issue. As I quote from link above "ASP can't recognize the results from MySQL and thinks it's EOF" without conversion from decimal to string.
For me it happened years ago With Oracle's Date/Time field having corrupt values causing this exact error when trying to select them.
Guess it's the same issue behind the scenes, what worked for me was manually deleting the corrupt rows using Oracle tools.
Another tip that has small chance to work is having such code instead:
adoCon.Open "DRIVER={MySQL ODBC 3.51 Driver}; SERVER=<SERVER_NAME>; PORT=<PORT_NUMBER>;" &_
"DATABASE=<DBNAME>; USER=<USERNAME>; PASSWORD=<PASS>; OPTION=3;"
Set rs = adoCon.Execute(SQL)
Hopefully the cursor used in this method won't crash.

Trouble resetting connection string in Access 2010

New to Access 2010. The following VBA code when run doesn't reset the connection string as expected. I'm pretty sure this used to work. What's wrong?
CurrentDb.TableDefs("AccountNumber").Connect = "ODBC;Description=NativeClient;DRIVER=SQL Native Client;SERVER=server1;DATABASE=Expense;Trusted_Connection=Yes"
CurrentDb.TableDefs("AccountNumber").RefreshLink
I am not sure about that connection string. Which version of SQL Server are you using? You might like to try a connection string from http://www.connectionstrings.com/sql-server-2008#p3, for example, this works for me.
scn = "Driver={SQL Server Native Client 10.0};" & _
"Server=ServerName; Database=test;Trusted_Connection=yes;"
With CurrentDb
.TableDefs(sLocalName).Connect = scn
.TableDefs(sLocalName).RefreshLink
End with

Visual Basic 2008 - NullReferenceException ERROR?

I'm using Visual Basic 2008 here, and I'm debugging my code that connects to my SQL Database and writes something in it. It was working fine and all until I came to an error like this. NullReferenceException was unhandled. What's going on? Here is the code I'm working with:
Dim conn As MySqlConnection
conn = New MySqlConnection
conn.ConnectionString = "server=...; user id=...; password=...; database=..."
Try
conn.Open()
Catch myerror As MySqlException
MsgBox("Error connecting to database")
End Try
Dim myAdapter As New MySqlDataAdapter
Dim sqlquery = "SELECT * FROM user WHERE username = '" + TextBox2.Text + "'"
Dim myCommand As New MySqlCommand()
myCommand.Connection = conn
myCommand.CommandText = sqlquery
myAdapter.SelectCommand = myCommand
Dim myData As MySqlDataReader
myData = myCommand.ExecuteReader()
It highlights it right around conn.open(), and gives me that error. It was working fine earlier until I moved my sql database to my mac. (windows -> mac) Is there a difference? I backed up my stuff from my windows vista computer and restored it on my mac. I don't think there is a difference, but I'm just putting that out there. Why does this error come up?
Thanks,
Kevin
I would suggest reviewing your connection string. I used your code and connected to our local MYSQL db no errors.
I can't really say what the problem is off the top of my head.
But the way to find out would be to put a breakpoint on the conn=New MySqlConnection and look at the variables you have as you step through.
If the problem is happening on the conn.Open line then it would probably be because conn is null (nothing). But if that is the case then conn.ConnectionString should have thrown an exception.
The other step is to look at the stack trace of the exception and see where, exactly, it is being thrown from. It could, for example, be an error somewhere inside the mysql connector.
Sorry I can't really give you a definate answer, but I thought some general comments might help you to the solution or find some more detail.
Whivh version of MySql are you using? Have you looked at the details of this bug...
http://bugs.mysql.com/bug.php?id=26393
... which is related to idle time.
If you had the full stack trace associated with the exception then it might shed some light on the problem.