although I did read plenty of stackoverflow posts and also checked out lots of tutorial websites I can't get my code to work.
I want to use sqlBulkCopy. And therefor I need a instance of the 'SqlConnection' class. I have a MySQL Database running and I have no problem at all opening a connection with the 'MySqlConnection' class.
I have tried several approaches to get SqlConnection working.
MySqlConnection (works):
Dim a = "Server=localhost;Initial Catalog=hauptdatenbank;User Id=johnny;Password=123456;"
Using cn As New MySqlConnection(a)
cn.Open()
End Using
SqlConnection (does not work):
Dim a = "Server=localhost;Initial Catalog=hauptdatenbank;User Id=johnny;Password=123456;"
Using cn As New SqlConnection(a)
cn.Open()
End Using
Following SqlException gets thrown:
A network-related or instance-specific error occurred while establishing a connection to SQL Server. The server was not found or was not accessible. Verify that the instance name is correct and that SQL Server is configured to allow remote connections. (provider: Named Pipes Provider, error: 40 - Could not open a connection to SQL Server)
SqlBulk is only for a SQL DB. MySqlBulkLoader is for a MySQL DB.
Thanks for the comments!
Imports MySql.Data.MySqlClient
Module Connection
Public str1 As String = "data source=localhost;user id= root;password=;database= parisbugdb;"
End Module
If Len(Trim(PassBox.Text)) = 0 Then
AlertLabel.Visible = True
AlertLabel.Text = "Password required!"
PassBox.SelectAll()
PassBox.Focus()
Return
End If
con.Open()
Dim Sql = "SELECT * FROM userx WHERE username ='" & UserBox.Text & "' AND password = '" & PassBox.Text & "'"
scmd = New MySqlCommand(sql, con)
Dim sdr As MySqlDataReader = scmd.ExecuteReader
Try
If sdr.Read = False Then
AlertLabel.Visible = True
AlertLabel.Text = "Login denied!"
con.Close()
Else
UserBox.Clear()
PassBox.Clear()
UserBox.Focus()
Me.Hide()
Dashboard.Show()
End If
Catch ex As Exception
MsgBox(ex.ToString())
End Try
End Sub
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.