|
-
Sep 4th, 2001, 09:04 PM
#1
Thread Starter
Lively Member
How to Create a DSN from VB...
Hi Guys,
I need to know is there any way to create a DSN for a Database (For Example Oracle or Access) using API. Is there any API for doing this. Otherwise any other method should be used. Additionally for Access we need to specify the Database Name. But for Oracle it is not needed. How should we check for the Existence of Oracle on a Machine ? First of all Is it Possible. Thnx in advance for any help.
-
Sep 5th, 2001, 06:28 AM
#2
Fanatic Member
Crispin
VB6 ENT SP5
VB.NET
W2K ADV SVR SP3
WWW.BLOCKSOFT.CO.UK
[Microsoft Basic: 1976-2001, RIP]
-
Sep 5th, 2001, 06:33 AM
#3
Here is some code that will either create, or delete, a DSN for Oracle:
Private Const ODBC_ADD_DSN = 1 ' Add data source
Private Const ODBC_CONFIG_DSN = 2 ' Configure (edit) data source
Private Const ODBC_REMOVE_DSN = 3 ' Remove data source
Private Const vbAPINull As Long = 0& ' NULL Pointer
Private Declare Function SQLConfigDataSource Lib "ODBCCP32.DLL" (ByVal hwndParent As Long, ByVal fRequest As Long, ByVal lpszDriver As String, ByVal lpszAttributes As String) As Long
Private Sub CreateDSN(sDSN As String)
Dim nRet As Long
Dim sDriver As String
Dim sAttributes As String
sDriver = "Oracle73 Ver 2.5"
sAttributes = "Server=pressdb.world" & Chr$(0)
sAttributes = sAttributes & "DESCRIPTION=" & sDSN & Chr$(0)
sAttributes = sAttributes & "DSN=" & sDSN & Chr$(0)
sAttributes = sAttributes & "DATABASE=DB" & Chr$(0)
sAttributes = sAttributes & "UID=Waty" & Chr$(0)
sAttributes = sAttributes & "PWD=myPassword" & Chr$(0)
DBEngine.RegisterDatabase "kiki", "Oracle73 Ver 2.5", True, sAttributes
nRet = SQLConfigDataSource(vbAPINull, ODBC_ADD_DSN, sDriver, sAttributes)
End Sub
Private Sub DeleteDSN(sDSN As String)
Dim nRet As Long
Dim sDriver As String
Dim sAttributes As String
sDriver = "Oracle73 Ver 2.5"
sAttributes = sAttributes & "DSN=" & sDSN & Chr$(0)
nRet = SQLConfigDataSource(vbAPINull, ODBC_REMOVE_DSN, sDriver, sAttributes)
End Sub
-
Sep 6th, 2001, 11:09 AM
#4
Frenzied Member
Perhaps you should look at connecting using a DSN-Less connection, and storing the configuration information in the registry.
You get to use OLE-DB then which with ADO has far superior performance.
-
Sep 6th, 2001, 09:33 PM
#5
Thread Starter
Lively Member
Can u tell me How should I use a OLE-DB Connection...
Hi yrwyddfa,
Can u give me a example on how should I use a OLE-DB Connection. Thnx in Advance.
-
Sep 7th, 2001, 02:55 AM
#6
Frenzied Member
Ora
I can't test this, because I haven't got Oracle, but I guess it would be something like this:
VB Code:
Function GetCn( _
ByVal sServer As String, _
ByVal sDatabase As String, _
ByVal sUID As String, _
ByVal sPassword As String _
) _
As ADODB.Connection
Dim oCn As ADODB.Connection
Dim sCn As String
Set oCn = CreateObject("ADODB.Connection")
oCn.Provider = "MSDAORA"
oCn.Properties("User ID") = "Waty"
oCn.Properties("Data Source") = "pressdb.world"
oCn.Properties("Initial Catalog") = "DB"
oCn.Open
If oCn.State <> adStateOpen Then
'raise errors here
Set GetCn = Nothing
Else
Set GetCn = oCn
End If
End Function
I hope this helps a little.
-
Sep 8th, 2001, 04:23 AM
#7
Thread Starter
Lively Member
Thnx yrwyddfa, I'll try it and mail you...
Hi yrwyddfa,
I got ur code and mail u after I got it working. Thnx for ur help.
Regards,
Ramanan.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|