none
Creating DSN to SQL Server in the code RRS feed

  • Question

  • Hi,

    i have some code for creating system DSN for sql server programmatically in VB.Net that i have searched on Internet.....

     

      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

     

    above code is working fine if user id and password attribute not supplied...

     

    can someone help me how i can create system DSN for sql server programmatically in VB.Net with UserId and Password.

    Please provide me solution for this.

     

    Thanks.

    Saturday, December 22, 2007 6:11 AM

Answers

  • I don't believe that Uid and Pwd are supported when using the ODBC API and the SQL Server ODBC driver. Apparently it requires writing this information to the Registry, which could be a security issue.
    Monday, December 24, 2007 5:17 PM

All replies

  • I don't believe that Uid and Pwd are supported when using the ODBC API and the SQL Server ODBC driver. Apparently it requires writing this information to the Registry, which could be a security issue.
    Monday, December 24, 2007 5:17 PM
  • please tell me clearly .....

    is It possible or not to Create DSN to SQL server programmatically in VB.net with userid and password on the sql server database.....

    and what will be the code for writing registry....is writing registry will solve the problem....

     

    please help me...

     

    thanks

     

    Wednesday, December 26, 2007 11:16 AM
  • Sorry for the late response, but just to confirm no I'm not aware of any way to save the user ID and password.

     

    Thursday, January 3, 2008 6:37 PM