Results 1 to 9 of 9

Thread: How to create an DSN?

  1. #1

    Thread Starter
    Frenzied Member cssriraman's Avatar
    Join Date
    Jun 2005
    Posts
    1,465

    How to create an DSN?

    Hi all,

    How to create a DSN programmatically?

    I need to create a system DSN in about 100 systems. So, If I create a program to do that it will be easier for me. So, pls help me to do that!

    Thanks,

    CS.

  2. #2
    Super Moderator si_the_geek's Avatar
    Join Date
    Jul 2002
    Location
    Bristol, UK
    Posts
    41,974

    Re: How to create an DSN?

    You don't actually need to use DSN's at all. You can connect to most (all?) databases by simply specifying the relevant information in a connection string.

    This not only makes your "nightmare" installation easier, it also bypasses the problem of ODBC being removed in future (which is likely to happen, especially in 64bit Windows).

    You may be able to find the details you need in the Connection Strings link below, if not give us more details

  3. #3
    Hyperactive Member
    Join Date
    May 2005
    Posts
    307

    Re: How to create an DSN?

    i used this to create my DSN. then just called Connect on my main form. works fine for me. Its for an access database. think it will work well for others as well

    VB Code:
    1. Private Declare Function SQLConfigDataSource Lib "ODBCCP32.DLL" _
    2.     (ByVal hwndParent As Long, ByVal fRequest As Long, _
    3.     ByVal lpszDriver As String, ByVal lpszAttributes As String) As Long
    4.     Public DB As ADODB.Connection
    5.     Public connString As String
    6.  
    7. Public Sub Connect()
    8.     Call Create
    9.    
    10.     connString = "DSN=VRRS;"
    11.     Set DB = New ADODB.Connection
    12.     DB.Open connString
    13. End Sub
    14.  
    15. Private Function CreateAccessDSN(DSNName As String, DatabaseFullPath As String) As Boolean
    16.     Dim sAttributes As String
    17.     sAttributes = "DSN=" & DSNName & Chr(0)
    18.     sAttributes = sAttributes & "DBQ=" & DatabaseFullPath & Chr(0)
    19.     CreateAccessDSN = CreateDSN("Microsoft Access Driver (*.mdb)", sAttributes)
    20. End Function
    21.  
    22. Private Function CreateDSN(Driver As String, Attributes As String) As Boolean
    23.     CreateDSN = SQLConfigDataSource(0&, 1, Driver, Attributes)
    24. End Function
    25.  
    26. Private Sub Create()
    27.     Dim blnRetVal As Boolean
    28.     blnRetVal = CreateAccessDSN("VRRS", "C:\VRRS\VRRS.mdb")
    29. End Sub

  4. #4

    Thread Starter
    Frenzied Member cssriraman's Avatar
    Join Date
    Jun 2005
    Posts
    1,465

    Re: How to create an DSN?

    Ok, fine! this is for Access. what about Oracle? Thanks a lot. CS.

  5. #5
    Super Moderator si_the_geek's Avatar
    Join Date
    Jul 2002
    Location
    Bristol, UK
    Posts
    41,974

    Re: How to create an DSN?

    Using one of these connection strings (instead of using a data source) should work for you, thus eliminating the need to set up a DSN as part of your installation:

    "Driver={Microsoft ODBC for Oracle};Server=OracleServer.world;Uid=Username;Pwd=password;"

    "Driver={Microsoft ODBC Driver for Oracle};ConnectString=OracleServer.world;Uid=myUsername;Pwd=password;"

  6. #6

    Thread Starter
    Frenzied Member cssriraman's Avatar
    Join Date
    Jun 2005
    Posts
    1,465

    Re: How to create an DSN?

    I use ADO code to connect my access database. so, what is the connection string to eliminate the DSN?
    CS

  7. #7
    Software Carpenter dee-u's Avatar
    Join Date
    Feb 2005
    Location
    Pinas
    Posts
    11,127

    Re: How to create an DSN?

    Have you tried te suggestions in Post #5? You could also take a look at www.connectionstrings.com for guidance...
    Regards,


    As a gesture of gratitude please consider rating helpful posts. c",)

    Some stuffs: Mouse Hotkey | Compress file using SQL Server! | WPF - Rounded Combobox | WPF - Notify Icon and Balloon | NetVerser - a WPF chatting system

  8. #8

    Thread Starter
    Frenzied Member cssriraman's Avatar
    Join Date
    Jun 2005
    Posts
    1,465

    Re: How to create an DSN?

    Thanks! great site!
    CS

  9. #9
    Software Carpenter dee-u's Avatar
    Join Date
    Feb 2005
    Location
    Pinas
    Posts
    11,127

    Re: How to create an DSN?

    No worries...
    Regards,


    As a gesture of gratitude please consider rating helpful posts. c",)

    Some stuffs: Mouse Hotkey | Compress file using SQL Server! | WPF - Rounded Combobox | WPF - Notify Icon and Balloon | NetVerser - a WPF chatting system

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width