Construct the Connection String at Runtime

0 comments

Posted on 5th July 2011 by Admin in Visual Basic .Net

, ,

‘How to Prompt user to construct the connection string at runtime!!!

‘It uses the same interface that ADODC, DataEnvironment etc use.

‘References:
’1. Microsoft OLE DB Service Component 1.0
’2. Microsoft ADO 2.5

‘Visual Basic Code Below


Public Function GetConnectionString(Optional strOLE As String = “OLEDB”) As String
On Error GoTo ErrHandler

Dim Conn As ADODB.Connection
Dim ObjectDataLink As MSDASC.DataLinks
Set Conn = New ADODB.Connection
Set ObjectDataLink = New MSDASC.DataLinks
Select Case strOLE
Case “OLEDB”
Conn = ObjectDataLink.PromptNew
GetConnectionString = Conn.ConnectionString
Case “ODBC”
Conn.ConnectionString = “”
Conn.Properties(“Prompt”) = adPromptAlways
Conn.Open
GetConnectionString = Conn.ConnectionString
Conn.Close
End Select
Exit Function
ErrHandler:
If Err.Number = 91 Or Err.Number = -2147217842 Then
Exit Function
Else
MsgBox “Error: “ & Err.Description
End If

End Function

Connect to a Secure Access Database Using ADO

0 comments

Posted on 30th April 2010 by Admin in Database Programming |Visual Basic 6

, ,

A secure Access database is one which in which the database and its users, groups, and permissions are created and set via an .mdw file. This code shows you how to access a secure Access database via ADO. It provides a workaround for the bug described by the Microsoft knowledge base article.

Type: Snippets
Author: Brad

Download File