Dynamically connect to SQL Server DB

Clovertech Forums Read Only Archives Cloverleaf Cloverleaf Dynamically connect to SQL Server DB

  • Creator
    Topic
  • #53475
    Brian Sweetland
    Participant

      This is my first ODBC project and to connect to my MS SQL Server 2008 DB, I

    Viewing 3 reply threads
    • Author
      Replies
      • #77799
        David Barr
        Participant

          If you get the ODBC license from Infor then you get DataDirect Connect which doesn’t require setting up a DSN in Windows. I always define my data sources in odbc.ini, but there may be a way to connect dynamically.

        • #77800
          Jim Kosloskey
          Participant

            I thought Windows had an odbc.ini file.

            However we are on AIX and use the Data Integrator (Data Direct) ODBC Drivers. We do specify the DB characteristics dynamically at connect time and only use the odbc.ini file to contain the base specifications for various types of DBs. Thus we have one entry for Oracle, one for SQL/Server, one for DB2, etc.

            Then at connection time we gather arguments provided which override what is in the defautl DNS in the odbc.ini file.

            This way we don’t need to worry about any screwup in the maintenance of the odbc.ini file since there is no maintenance required.

            email: jim.kosloskey@jim-kosloskey.com 29+ years Cloverleaf, 59 years IT - old fart.

          • #77801
            Sergey Sevastyanov
            Participant

              Brian,

              I use tclodbc to run queries against SQL Server 2008 and I don’t use ODBC System Data Source.

              If you want to use SQL Server Authentication you can set connection string like this (variables server, database, uid, pwd set to server name, database name, user id and password):

              Code:


              set connect_string “Driver={SQL Server};Server=$server;Database=$database;
              Uid=$uid;Pwd=$pwd;”

              If you want to connect using integrated security then set connection like this:

              Code:


              set connect_string “Driver={SQL Server};server=$server; database=$database;
              Integrated Security=True;Trusted_Connection=Yes”

              I prefer the latter – that way I don’t need to store password anywhere.

              Then you connect to the database like this:

              Code:


              set db [database connect db $connect_string]

              Hope this helps

            • #77802
              Sergey Sevastyanov
              Participant

                Brian,

                Just to be clear – my example is for tclodbc library.

                You have to add “package require tclodbc” to use it. From your code it looks like you use a different library

            Viewing 3 reply threads
            • The forum ‘Cloverleaf’ is closed to new topics and replies.