I'm trying to connect my local .mdf file to vb.net and this argument exception pops up "Keyword not supported. Parameter name: attachdbfilename"
here's my code
Imports MySql.Data.MySqlClient
Public Class Form1
Dim con As MySqlConnection
Private Sub PictureBox1_Click_1(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles PictureBox1.Click
con = New MySqlConnection
con.ConnectionString = "Data Source=.\SQLEXPRESS;AttachDbFilename=C:\Users\almond\Desktop\TICKETING SYSTEM\TICKETING SYSTEM\Database1.mdf;Integrated Security=True;User Instance=True"
Try
con.Open()
MessageBox.Show("Connected!")
con.Close()
Catch ex As MySqlException
MessageBox.Show(ex.Message)
Finally
con.Dispose()
End Try
End Sub
The problem is you are using MySqlConnection
, and that only must be used with MySql
databases. You must use SqlConnection
:
Imports System.Data.SqlClient;
Public Class Form1
Dim con As SqlConnection
Private Sub PictureBox1_Click_1(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles PictureBox1.Click
con = New SqlConnection
con.ConnectionString = "Data Source=.\SQLEXPRESS;AttachDbFilename=C:\Users\almond\Desktop\TICKETING SYSTEM\TICKETING SYSTEM\Database1.mdf;Integrated Security=True;User Instance=True"
Try
con.Open()
MessageBox.Show("Connected!")
con.Close()
Catch ex As SqlException
MessageBox.Show(ex.Message)
Finally
con.Dispose()
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.