Need to automatically create (programmatically) a DSN within the system ODBC -VB .NET

Discussion in 'OT Technology' started by VBGOD, May 4, 2003.

Thread Status:
Not open for further replies.
  1. VBGOD

    VBGOD Guest

    :mad:

    [​IMG]
    Clean

    [​IMG]
    Manually entered.

    [​IMG]
    Done.


    OK..... I've done this before in both VB 5.0 and 6, but the current API function SQLConfigDataSource is dead. :-/

    C# code would also be welcomed here. :hs:
     
  2. court-jester

    court-jester I love dykes

    Joined:
    May 5, 2000
    Messages:
    18,166
    Likes Received:
    0
    Location:
    toronto registered: March 1998
    i use odbc less connection but its just to access DB :dunno:

    ADOConn.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;" & _
    "User ID=;" & _
    "Data Source=C:\timemanagerNEW\TimeManager.mdb"
    ADOConn.Open
     
  3. VBGOD

    VBGOD Guest

    That's kiddie stuff. I'm trying to create a DSN for an SQL Server. :hs:
     
  4. VBGOD

    VBGOD Guest

    Read: not the connection string, but the actual entry within the system's ODBC. :hs:
     
  5. VBGOD

    VBGOD Guest

    I'll be back later. I expect 5 more responses, followed by the crushing feeling of no solution.
     
  6. court-jester

    court-jester I love dykes

    Joined:
    May 5, 2000
    Messages:
    18,166
    Likes Received:
    0
    Location:
    toronto registered: March 1998
    Code:
    Private Const ODBC_ADD_DSN = 1        ' Add data source
    Private Const ODBC_CONFIG_DSN = 2     ' Configure (edit) data source
    Private Const ODBC_REMOVE_DSN = 3     ' Remove data source
    Private Const ODBC_ADD_SYS_DSN = 4     ' Configure (edit) data source
    Private Const ODBC_REMOVE_SYS_DSN = 6     ' Remove data source
    
    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 strDSNName As String, ByVal strDatabaseLoc
    As String) As Boolean
       Dim intRet As Long
       Dim strAttributes As String
    
       strAttributes = "DSN=" & strDSNName & Chr$(0)
       strAttributes = strAttributes & "DBQ=" & strDatabaseLoc
    
       intRet = SQLConfigDataSource(vbAPINull, ODBC_ADD_SYS_DSN, scDriverName,
    strAttributes)
    
       If intRet Then
           CreateDSN = True
       Else
           CreateDSN = False
       End If
    End Function
    
    :dunno:
     
  7. VBGOD

    VBGOD Guest

    That's over 5+ years old, and won't work with VB .NET :hs:

    Thanks anyways.
     
  8. court-jester

    court-jester I love dykes

    Joined:
    May 5, 2000
    Messages:
    18,166
    Likes Received:
    0
    Location:
    toronto registered: March 1998
  9. VBGOD

    VBGOD Guest

    I tried that one a looooooooong time ago. :(

    In fact, no search engine can help me out here. I need a person that has actually done a VB .NET solution. Thanks again. :hs:
     
  10. ///TRASH

    ///TRASH Hideously Erect

    Joined:
    Jan 20, 2001
    Messages:
    39,120
    Likes Received:
    433
    Location:
    San Diego, California
    wrong forum :hs:
     
  11. ///TRASH

    ///TRASH Hideously Erect

    Joined:
    Jan 20, 2001
    Messages:
    39,120
    Likes Received:
    433
    Location:
    San Diego, California
  12. VBGOD

    VBGOD Guest

    I know... but I'm so desperate.
     
  13. court-jester

    court-jester I love dykes

    Joined:
    May 5, 2000
    Messages:
    18,166
    Likes Received:
    0
    Location:
    toronto registered: March 1998
    ur no VBGOD! more like VBPEON!
     
  14. Jago

    Jago It helps if you hit it.

    Joined:
    Jun 3, 2000
    Messages:
    27,965
    Likes Received:
    0
    the funny thing is our admin at work can do this blindfolded. too bad i'm no where near his level. :(
     
  15. VBGOD

    VBGOD Guest

    SLED, Cakennedy
     
  16. CompiledMonkey

    CompiledMonkey New Member

    Joined:
    Oct 26, 2001
    Messages:
    8,528
    Likes Received:
    0
    Location:
    Richmond, VA
    Bump for the man. :hs:
     
  17. Mugatu

    Mugatu Ask me about market research. OT Supporter

    Joined:
    Oct 21, 2001
    Messages:
    245,192
    Likes Received:
    0
    :rofl: :o
     
  18. VBGOD

    VBGOD Guest

    Got It!!!!!!!!!!!!!!!!
     
  19. CompiledMonkey

    CompiledMonkey New Member

    Joined:
    Oct 26, 2001
    Messages:
    8,528
    Likes Received:
    0
    Location:
    Richmond, VA
    Post the code!
     
  20. SLED

    SLED build an idiot proof device and someone else will

    Joined:
    Sep 20, 2001
    Messages:
    28,118
    Likes Received:
    0
    Location:
    AZ, like a bauce!
Thread Status:
Not open for further replies.

Share This Page