none
System.InvalidOperationException RRS feed

  • Question

  • I get this error when I connect to a db.mdf and try to open the connection.

    The .net framework data provider sql server data source provider not registered on the local machine.

    What can I do?

    Thursday, June 14, 2018 9:47 PM

All replies

  • I get this error when I connect to a db.mdf and try to open the connection.

    The .net framework data provider sql server data source provider not registered on the local machine.

    What can I do?


    Like show the code and the and the app.config?
    Thursday, June 14, 2018 10:24 PM
  • Hi doug,

    How did you connect the database to your project?

    Try this:

    Imports System.Data.SqlClient
    
    Public Class Form4
        Dim sqlCon As String = "Data Source=(LocalDB)\MSSQLLocalDB;AttachDbFilename=D:\DAL\Database100.mdf;Integrated Security=True"
    
        Private Sub button1_Click(sender As Object, e As EventArgs) Handles button1.Click
            Dim sqlSelect As String = "select * from Table1 where Age=" & Convert.ToInt32(textBox1.Text)
            BindData(sqlCon, sqlSelect)
        End Sub
    
        Public Sub BindData(sqlCon As String, sqlSelect As String)
            Dim dt As New DataTable()
            Dim ds As New DataSet()
            Using conn As New SqlConnection(sqlCon)
                Using cmd As New SqlCommand(sqlSelect, conn)
                    Using adapter As New SqlDataAdapter(cmd)
                        adapter.Fill(ds)
                        dt = ds.Tables(0)
                        conn.Close()
                    End Using
                End Using
            End Using
            dataGridView1.DataSource = dt
        End Sub
    End Class

    Regards,

    Frankie


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Friday, June 15, 2018 8:23 AM
  • Hello,

    Try opening a command console e.g. Windows key + R, type cmd press enter. Now type SqlLocalDb versions.

    Once you have the version, check out the connection strings for localdb at the following link.

    https://www.connectionstrings.com/sql-server/

    Example

    Server=(localdb)\v11.0;Integrated Security=true;AttachDbFileName=C:\MyFolder\MyData.mdf;


    Please remember to mark the replies as answers if they help and unmark them if they provide no help, this will help others who are looking for solutions to the same or similar problem. Contact via my Twitter (Karen Payne) or Facebook (Karen Payne) via my MSDN profile but will not answer coding question on either.
    VB Forums - moderator
    profile for Karen Payne on Stack Exchange, a network of free, community-driven Q&A sites

    Friday, June 15, 2018 9:03 AM
    Moderator