Results 1 to 9 of 9
  1. #1
    DinoZon is offline Novice
    Windows XP Access 2007
    Join Date
    Feb 2014
    Posts
    2

    Display ODBC Data Source System DSN Name on Access Form

    Hello,



    Does anyone know how to retrieve and display the current ODBC Data Source System DSN Name on an Access form? I have an access form that people will be using to test in different environments and would like to display their connection name so they know which environment they are logged into.

    Thank you.

  2. #2
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,929
    Test this in the VBA immediate window:

    ?Application.CurrentProject.BaseConnectionString

    Is that the info you want? I doubt it. Seems to be the frontend not the backend.

    How do you establish connection? VBA or linked tables?
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  3. #3
    ipisors is offline Access Developer
    Windows XP Access 2007
    Join Date
    Sep 2013
    Posts
    119
    DinoZon,

    I think this question needs more specifics to it. People can have many DSNs set up on their computer, so...Which one would you be wanting? At my current FTE the average person has about 8 DSNs set up at a minimum, I have about 30 or more.

    Are you perhaps thinking of whichever Connect property is associated with one particular table of the database table links? The Connect property of whatever table is underlying the current form? (are you sure the Form's recordsource is a simple table?, if not it doesn't make sense)

    More specifics please...a database doesn't have just "one dsn" - in fact a database in general doesn't rely on a DSN. LInked tables do...some code may...but you haven't specified this or what yet.

    thanks

  4. #4
    DinoZon is offline Novice
    Windows XP Access 2007
    Join Date
    Feb 2014
    Posts
    2
    Sorry, I should have included more details. I have an access front end that connects to an Oracle back-end through linked tables. We have 3 different environments, production, test, and development, and 3 different ODBC System DSN connections named after the servers themselves. When users log into the application they have to log in through the Oracle ODBC Driver Connect login screen. The Service Name identifies which server they are connecting to, which would be either TDSAD (development), TDSAT (test), or TDSAP (production). It is the TDSAD, TDSAT, OR TDSAP that I would like to display on the Access forms so they know which environment they are logged into

  5. #5
    Xipooo's Avatar
    Xipooo is offline Sr. Database Developer
    Windows 8 Access 2013
    Join Date
    Jan 2014
    Location
    Arizona
    Posts
    332
    A FORM doesn't have an ODBC connection, but the data behind it might. If you are using an Access query for the data source of your form, then you can look in currentdb.querydefs("<queryname>").connect property to find the ODBC connection string being used for that query.

    If you are making your own query string and not using a stored query in Access then you will have to look at the individual tables being referenced in your query by looking at currentdb.tabledefs("<tablename>").connect property to find the ODBC connection string being used for that table.

    FWIW, for easier use I have found going DSN-less and programing in your ODBC connection strings is a bit more manageable. I don't like going around to every PC on the network and making sure the DSN's are all set up correctly. Conversely if you have a decent domain admin he/she can use Group Policy to create the DSN's.

  6. #6
    orange's Avatar
    orange is offline Moderator
    Windows XP Access 2003
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,726
    I'm not sure if this applies to your situation, but I set up a routine that let me work with whichever Oracle environment I needed. We had 4 environments.

    stratdev1 DEVL..........Develoment
    stratpre1 STRTPRE.....PreProduction/Maintenance
    strategis SGIP...........Corporate Production
    stratuat SUAT.........User Acceptance Testing

    I've been retired for a number of years, but this was part of the code involved.

    Code:
    '---------------------------------------------------------------------------------------
    ' Procedure : RelinkCOCATables
    ' DateTime  : 2006-01-03 17:19
    ' Author    : j
    ' Purpose   : Relink all existing COCA_DBA tables in the proper Oracle environment
    '
    'Parm:  Env   string
    '        stratdev1     DEVL
    '        stratpre1     STRTPRE
    '        strategis     SGIP
    '        stratuat      SUAT
    '---------------------------------------------------------------------------------------
    '
    Sub RelinkCOCATables(Env As String)
    
    Dim connectEnv As String 'environment to connect to
    Dim cocaDev As String    'current coords DEVL
    Dim cocaPre As String    'current coords STRTPRE
    Dim cocaProd As String   'current coords SGIP
    Dim cocaUat As String    'current coords SUAT
    Dim Msg As String        'msg string to show activity
    Dim sResponse As String  'response to msg buttons
    Dim tbl As DAO.TableDef
    Dim db As DAO.Database
    Set db = CurrentDb
    
    'Oracle Tables ODBC
    cocaDev = "Ora901 devl;PWD=XXXXX;"
    cocaPre = "Ora901 strtpre;PWD=YYYYYY;"
    cocaProd = "Ora901 sgip;PWD=PPPPPPP;"
    cocaUat = "Ora901 suat;PWD=WWWWWWW;"
    
    Select Case Env
      Case "stratdev1"
       connectEnv = cocaDev
       Case "stratuat"
       connectEnv = cocaUat
      Case "stratpre1"
       connectEnv = cocaPre
      Case "strategis"
       connectEnv = cocaProd
      Case Else
     End Select
       
    ' -- RELINK EACH COCA_DBA TABLE
    For Each tbl In db.TableDefs
         If tbl.Name Like "COCA_DBA*" Then
         'drop current linked table
            DoCmd.RunSQL ("DROP TABLE " & tbl.Name)
         'relink the table in proper environment
            DoCmd.TransferDatabase acLink, "ODBC Database", _
             "ODBC;UID=COCA_USER;DSN=" & connectEnv, _
             acTable, "COCA_DBA." & Mid(tbl.Name, 10), _
             tbl.Name, , True
             Msg = Msg & Mid(connectEnv, 1, InStr(connectEnv, ";")) & "  Relinked : " & tbl.Name & vbCrLf
         Else
         End If
    Next tbl

  7. #7
    ipisors is offline Access Developer
    Windows XP Access 2007
    Join Date
    Sep 2013
    Posts
    119
    Coming back late to the talk, but my 2 cents -
    Thanks for the extra info. I see now somewhat what you are dealing with.

    1. I have no idea how you'd track this Oracle login screen, sorry.
    2. Can you use a different approach? Create a function that tests their ability to all 3 tables. The 2 that fail means they aren't connected to X or Y, the one that succeeds means they are connected to Z. Not sophisticated, but simple as heck. When you can't answer a question directly by programming, sometimes a very simple function can answer it indirectly.... (similar example...when I want to see if a user has access to a folder before a procedure starts, I don't use any fancy ad-ent code, I just run a boolean function that attempts to create and delete a text file in that location and trap the error. Works like a charm).
    3. Interesting comment on DSN-less -- I certainly agree, I'd advise anyone to take advantage of this any time they can. I've found it of limited value because the DB's I have that utilize some serious RDBMS's in the first place (like at my full time jobs), are so mixed - some SQL server, DB2, Oracle, Access - that the DSN-less code I've found, I just couldn't quite get it to work for Oracle given our setup. But if all you had were sql server it's much easier.

  8. #8
    Xipooo's Avatar
    Xipooo is offline Sr. Database Developer
    Windows 8 Access 2013
    Join Date
    Jan 2014
    Location
    Arizona
    Posts
    332
    Quote Originally Posted by ipisors View Post
    Coming back late to the talk, but my 2 cents -
    ...
    3. Interesting comment on DSN-less -- I certainly agree, I'd advise anyone to take advantage of this any time they can. I've found it of limited value because the DB's I have that utilize some serious RDBMS's in the first place (like at my full time jobs), are so mixed - some SQL server, DB2, Oracle, Access - that the DSN-less code I've found, I just couldn't quite get it to work for Oracle given our setup. But if all you had were sql server it's much easier.
    In those situations, we set up linked servers on the MS SQL server. That way we have one point of entry for all our data and a much more powerful SQL engine is handling the operations. OPENQUERY is your friend.

  9. #9
    ipisors is offline Access Developer
    Windows XP Access 2007
    Join Date
    Sep 2013
    Posts
    119
    Quote Originally Posted by Xipooo View Post
    In those situations, we set up linked servers on the MS SQL server. That way we have one point of entry for all our data and a much more powerful SQL engine is handling the operations. OPENQUERY is your friend.
    Well we do have a lot of linked sql servers but unfortunately, none linked to other rdbms. would be nice, but i have nothing to do with authority on that setup. ;(

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Change source of ODBC data
    By Alan Cannon in forum Access
    Replies: 1
    Last Post: 07-15-2013, 02:46 PM
  2. Replies: 0
    Last Post: 12-31-2012, 10:50 AM
  3. Replies: 3
    Last Post: 01-06-2012, 04:17 PM
  4. Replies: 1
    Last Post: 11-15-2011, 07:26 AM
  5. Replies: 5
    Last Post: 10-25-2011, 08:01 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums