12/29/2005

Create Jet database on the fly

Filed under: General — russell @ 1:32 am

I need to create a Jet Database on the fly so I can then run DTS to dump SQL Server data into it. Heres the code to do it after the jump

Need to add the ADO Extension com object

Code:
Public Function CreateAccessDatabase( _
    ByVal DatabaseFullPath As String) As Boolean
        Dim bAns As Boolean
        Dim cat As New ADOX.Catalog()
        Try
	
         'Make sure the folder
         'provided in the path exists. If file name w/o path
         'is  specified,  the database will be created in your
         'application folder.
	
            Dim sCreateString As String
            sCreateString = _
              "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & _
               DatabaseFullPath
            cat.Create(sCreateString)
	
            bAns = True
	
        Catch Excep As System.Runtime.InteropServices.COMException
            bAns = False
            'do whatever else you need to do here, log,
            'msgbox etc.
        Finally
            cat = Nothing
        End Try
        Return bAns
    End Function
'DEMO
'      If CreateAccessDatabase("F:\test.mdb") = True Then
'           MsgBox("Database Created")
'      Else
'           MsgBox("Database Creation Failed")
'      End If

No Comments »

No comments yet.

RSS feed for comments on this post.

Leave a comment

Couldn't find your convert utility. Check that you have ImageMagick installed.