none
Create USer DSN

    Question

  • Hi.
    Can somebody tell me how to create a system DSN for SQL Server programmatically in vb .net?
    The following code always fails to create the DSN. What am i missing?
      Private Sub Build_SystemDSN_SQL()
            Dim ret%, Driver$, Attributes$
            Driver = "SQL Server" & Chr(0)
            Attributes = "DSN=" & mstrDSNName & Chr(0)
            Attributes = Attributes & "Server=" & mstrServerName & Chr(0)
            Attributes = Attributes & "Database=" & mstrDBName & Chr(0)
            Attributes = Attributes & "Uid=" & mstrUser & Chr(0) & "pwd=" & mstrPwd & Chr(0)
            'Attributes = Attributes & "Trusted_Connection=yes"
            SQLConfigDataSource(0, ODBC_REMOVE_SYS_DSN, Driver, Attributes)
            ret = SQLConfigDataSource(0, ODBC_ADD_SYS_DSN, Driver, Attributes)

            'ret is equal to 1 on success and 0 if there is an error
            If ret <> 1 Then
                MsgBox("DSN Creation Failed")
            End If

        End Sub

    The above code fails to create the DSN if the user name and the password are supplied in the attribute. Otherwise the DSN is created. But i want to save/store the user name and password in the DSN. Any help is greatly appreciated.

    Thanks.

    Saturday, September 08, 2012 10:24 AM

Answers

All replies