Click here to Skip to main content
15,887,267 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have a code that looks like this that will create a system dsn that has a username and password. It works but when i looked in my created dsn, the login id and password have default values. Hope you'll help me guys.. thanks :)

VB
Private Shared Sub CreateSystemDSN()
    'create dsn programmatically
    Dim ReturnValue 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=" & dbServer & Chr(0)
    Attributes = Attributes & "DESCRIPTION=" & dbName & Chr(0)
    Attributes = Attributes & "DSN=" & dbName & Chr(0)
    Attributes = Attributes & "DATABASE=" & dbName & Chr(0)
'---> error part
    Attributes = Attributes & "TRUSTED_CONNECTION=NO" & Chr(0)
    Attributes = Attributes & "UID=" & dbUser & Chr(0)
    Attributes = Attributes & "PWD=" & dbPassword & Chr(0)
'---> end of error part
    'To show dialog, use Form1.Hwnd instead of vbAPINull.
    ReturnValue = SQLConfigDataSource(vbAPINull, ODBC_ADD_SYS_DSN, Driver, Attributes)
    If ReturnValue <> 0 Then
        MsgBox("DSN Created")
    Else
        MsgBox("Please contact administrator. ODBC Connection failed.")
    End If
End Sub
Posted
Updated 4-May-11 16:54pm
v2
Comments
walterhevedeich 3-May-11 21:54pm    
What do you mean it wont work? You have to provide some scenario and error message(s) that you encounter.
candice_Blav 4-May-11 22:54pm    
@walterhevedeich
sorry for my vague question... i've improved my question. hope you'll help me.

1 solution

 
Share this answer
 
Comments
candice_Blav 4-May-11 22:57pm    
Thanks for the solution Bryian Tan, I think the solution you gave me uses the registry. They don't want us to use that kind of method..

Right now i'm using
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
Hitesh Shroff 15-Jun-18 3:57am    
The link not working. @Bryian Tan

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900