Results 1 to 8 of 8

Thread: [RESOLVED] Database Connection Issue

Threaded View

  1. #1

    Thread Starter
    Member
    Join Date
    Dec 2009
    Location
    Ontario, Canada
    Posts
    54

    Resolved [RESOLVED] Database Connection Issue

    Can sombody please tell me where I am going wrong, please. I am trying to teach myself how to connect to a database that is not attached to my project.

    I am using VB2010 Express with SQL express.

    Here's the code I have;
    Code:
        Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
            Dim con As New OleDb.OleDbConnection
            Dim dbProvider As String
            Dim dbSource As String
            Dim ds As New DataSet
            Dim da As OleDb.OleDbDataAdapter
            Dim sql As String
            
            dbProvider = "PROVIDER=Microsoft.SQLEXPRESS;"
            ' I've tried other versions of provider names such as, Provider=SQLEXPRESS.  
            dbSource = "Data Source=C:\MarketPlaceDatabase.mdf"
    
            con.ConnectionString = dbProvider & dbSource
    
            con.Open()
            sql = "Select * From tblManagersTable"
            da = New OleDb.OleDbDataAdapter(sql, con)
    
            MsgBox("Database is now open")
            con.Close()
            MsgBox("Database is now closed")
    
        End Sub
    The form is simple, 1 single button on it. Press it and it is suppose to connect and display a message box, but I keep getting an error.

    Every project I have ever created has a SQL database attached to it so I a baffled to what is wrong. Also am wondering what the difference is between a MDF and MDB database extension. Mine always safe as a MDF, but all the articles I have read reference a MDB file.
    Attached Images Attached Images  

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width