Discussion Locked

how to Create Dsn through coading, Can any help me

0 helpful
2 replies
Closed to new repliesThis discussion is closed. It stays readable, but it takes no new replies.

How to create a DSN(Data Source Name) in VB without going to control panel->obdc32bit->etc
can i create a DSN through coding at runtime from VB Coading for sql server 2000?

plz forward ur suggestions.

Thanking You..

2 replies

by nsuguna

You should keep the registry entries which will be created when any DSN is created.
Use APIs like RegCreateKey etc.. to create the registry keys . This way you can create DSN thru program..Hope this answers if u r still waiting for solution..

by sudharsank

Sorry guy, I am from VB.Net i will provide u the code in vb.net

Private Declare Function SQLConfigDataSource Lib "ODBCCP32.DLL" (ByVal hwndParent As Integer, ByVal ByValfRequest As Integer, ByVal lpszDriver As String, ByVal lpszAttributes As String) As Integer

Private Const vbAPINull As Integer = 0 ' NULL Pointer

Private Const ODBC_ADD_DSN As Short = 1 ' Add data source
Public Sub CreateUserDSN()
Try
Dim intRet As Integer
Dim Driver As String
Dim Attributes As String
'Set the driver to SQL Server because it is most common.
Driver = "SQL Server"
'Set the attributes delimited by null.
'See driver documentation for a complete
'list of supported attributes.
Attributes = "SERVER=zsw327" & Chr(0)
Attributes = Attributes & "DATABASE=KFI" & Chr(0)
Attributes = Attributes & "DESCRIPTION=New DSN" & Chr(0)
Attributes = Attributes & "DSN=KFIDSN" & Chr(0)

intRet = SQLConfigDataSource(vbAPINull, ODBC_ADD_DSN, Driver, Attributes)
If intRet <> 0 Then
MsgBox("DSN Created")
Else
MsgBox("Create Failed")
End If
Catch ex As Exception
MsgBox(ex.Message)
End Try
End Sub

This discussion is closed to new replies.