create a DSN at runtime for oracle database
Hello, I have got this problem. can anybody give me a valid solution.
How to create a DSN at runtime for oracle database using visual basic.
# 1 Re: create a DSN at runtime for oracle database
hi,
Following Code may help you in this regards
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
public Function CreateDSN(byval pstrServer as string, byval pstrDescription as string, byval pstrDSN as string, byval pstrDataBase as string) as Long
'--------------------
'Arguments : pstrServer - string specifying the Server Name
' pstrDescription - string giving the Description to DSN
' pstrDSN - string giving name to DSN
' pstrDataBase - string specifying the Database for DSN.
'Return Value : 1 if successfull creation of DSN else 0.
'Procedure : Creates DSN for the specified Database and
' returns whether DSN has been created successfully or not.
'--------------------
on error resume next
Dim strDriver as string
Dim strAttributes as string
'set the driver to SQL Server because it is most common.
strDriver = "SQL Server"
'set the attributes delimited by null.
'See driver documentation for a complete
'list of supported attributes.
strAttributes = "SERVER=" & pstrServer & Chr(0)
strAttributes = strAttributes & "DESCRIPTION=" & pstrDescription & Chr(0)
strAttributes = strAttributes & "DSN=" & pstrDSN & Chr(0)
strAttributes = strAttributes & "DATABASE=" & pstrDataBase & Chr(0)
'Calls API to create DSN
CreateDSN = SQLConfigDataSource(vbAPINull, ODBC_ADD_DSN, _
strDriver, strAttributes)
End Function
'Call This Function on your button Click
sub command1_click()
dim RetValue as integer
Retvalue= CreateDSN("Localhost", "My DSN Version 1.14.3", "MYDSNNAME", "DBName")
end sub
programmer at MIND