Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Getting started - accessing a SQL database

Status
Not open for further replies.

collierd

MIS
Dec 19, 2001
509
DE
Hello

using VB.NET I have the following simple code:

Code:
 Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim con As New OleDb.OleDbConnection()
        Dim ds As New DataSet
        Dim da As OleDb.OleDbDataAdapter
        Dim sql As String

        con.ConnectionString = "PROVIDER=Microsoft.Jet.OLEDB.4.0;Data Source = C:\Test_SQL_Data.mdf"

        con.Open()

        sql = "SELECT * FROM Customers"
        da = New OleDb.OleDbDataAdapter(sql, con)

        MsgBox("A Connection to the Database is now open")

        con.Close()

        MsgBox("The Connection to the Database is now Closed")


    End Sub

I know the mdf file exists


It keeps returning the following error against con.Open():

Could not use ''; file already in use.

Does anybody know why?


Thanks

Damian.
 
A .MDF file is an SQL Server data file, whereas the connection string you are using looks more like an Access (.MDB) connection string.

I've never tried to access an SQL Server database in that way, and to be honest I'm not sure that you can.

The normal way to access SQL Server is via the connection string format provided by:


or



Hope this helps.

[vampire][bat]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top