Reputation: 19
So every time i try to write to the Database, running on MySQL the program give out an error(Fatal internal connection error).
This is the code being used :
Dim SQLcon As New SqlConnection("Server=127.0.0.1; Database=storedatabase; User Id=root; Password=root;")
Dim cmd As SqlCommand
Try
SQLcon.Open()
cmd.Connection = SQLcon
cmd.CommandText = "INSERT INTO Items (ItemName, ItemPrice, ItemQTY) VALUES ('" & Item & "','" & Price & "','" & Qty & "');"
SQLcon.Close()
MsgBox("Added " & Item & " to Database", MsgBoxStyle.Information)
Catch ex As Exception
MsgBox(ex.Message)
End Try
VB gives this error :
An exception (first chance) of type 'System.InvalidOperationException' occurred in System.Data.dll.
The SQL port is changed to 1433.
Database with tables exist.
EDIT : After adding the Port=1433 to the connection string i get this error :
InnerExecption = {"Keyword not supported: 'port'."}
Connection String :
Dim SQLcon As New SqlConnection("Server=127.0.0.7; Port=1433; Database=storedatabase; User Id=root; Password=root;")
Upvotes: 0
Views: 391
Reputation: 9322
Try, using uid
for UserID
and pwd
for Password
:
Dim SQLcon As New MySqlConnection("Server=127.0.0.1; Database=storedatabase; uid=root; pwd=root;")
See link
You need to use import at the Global Level of your class, like:
Imports MySql.Data.MySqlClient
I am assuming by the way that you are using MySQL connector since it is not native in dotNet unlike Sql server. Otherwise the Imports MySql.Data.MySqlClient
namespace will not work.
Upvotes: 0
Reputation: 1683
Bah, I'm an idiot.
You are trying to connect to a MySQL Database using MSSQL's client library. You need to use the MySql Connector:
http://dev.mysql.com/doc/refman/5.0/en/connector-net-programming-connecting-connection-string.html
Dim SQLcon As New MySql.Data.MySqlClient.MySqlConnection("Server=127.0.0.1; Port=1433; Database=storedatabase; User Id=root; Password=root;")
Dim cmd As SqlCommand
Upvotes: 1