Django Anonymous
Django Anonymous

Reputation: 3025

Sql connection error through binding source database connection

This is my code for connection:

Imports System.Data.SqlClient
Public Class frm_edit_patient
    Dim con As New SqlConnection
    Private Sub frm_edit_patient_FormClosing(ByVal sender As Object, ByVal e As System.Windows.Forms.FormClosingEventArgs) Handles Me.FormClosing
        frm_dashboard.Enabled = True
        Me.Hide()
    End Sub
    Private Sub frm_edit_patient_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        'TODO: This line of code loads data into the 'Database1DataSet1.patients' table. You can move, or remove it, as needed.
        Me.PatientsTableAdapter.Fill(Me.Database1DataSet1.patients)
        frm_dashboard.Enabled = False
        Try
            Dim myConString As String = My.Settings.Database1ConnectionString
            con.ConnectionString = myConString
            con.Open()
            con.Close()
            MessageBox.Show("connected")
        Catch ex As Exception
            MessageBox.Show(ex.ToString)
        End Try
    End Sub

    Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
        frm_dashboard.Enabled = True
        Me.Hide()
    End Sub
End Class

but this is giving me error:

enter image description here

I am using binding source for database connection....

Upvotes: 0

Views: 525

Answers (1)

Steve
Steve

Reputation: 216363

Database.sdf is a Sql Compact database file, not a Sql Server catalog name.

You need to use SqlCeConnection not a SqlConnection

Thus you need to declare

Dim con As New SqlCeConnection

also remember that you need a reference to the assembly System.Data.SqlServerCe
(in System.Data.SqlServerCe.dll)

Upvotes: 1

Related Questions