Results 1 to 16 of 16

Thread: A challenging question for experienced programmers only

  1. #1

    Thread Starter
    Frenzied Member maged's Avatar
    Join Date
    Nov 2002
    Location
    Egypt
    Posts
    1,040

    A challenging question for experienced programmers only

    hi all,

    i am trying to use ado.net to connect to a database, access 2k thru a dsn. ( the one that we make from the administration tasks in control panel)

    now after researching and many threads in many sites including this one. i found this bad news

    ADO . net doesn't support the ODBC layer, in other words i cannt use the class oledbconnection in connecting thru a dsn name.

    so i decided to go around the problem.

    i do know how to connect if i have the full path of the access database ( ex. : c:\docs\data.mdb) , thru thr microsoft.jet engine of course.


    so the important question, if i have the dsn name, how could i extract the file path from it. so i can overpass it and open my connection depending on the pass it points to

    help me out experienced people.

    i need help


    THX IN ADVANCE & BST RGDS

  2. #2
    Your Ad Here! Edneeis's Avatar
    Join Date
    Feb 2000
    Location
    Moreno Valley, CA (SoCal)
    Posts
    7,339
    This is not that experienced of a problem. Its true that the OLEDB data provider in .NET doesn't support ODBC but there is a .NET ODBC Data provider. Just use it instead of OLEDB. If you have VS.NET 2003 then it is built in to the .NET Framework otherwise you have to download it from the Microsoft website.

    http://www.microsoft.com/downloads/d...displaylang=en

    From there it works just like the SQLClient and OLEDB providers but is for use with ODBC.

  3. #3

    Thread Starter
    Frenzied Member maged's Avatar
    Join Date
    Nov 2002
    Location
    Egypt
    Posts
    1,040
    thx for the tip,

    anyway is it possible to perform what i wanr to do ?>?

    can i get the path of the file for the dsn???


    this may be very important in building my dbase class

    i would appreciate your help

    THX

  4. #4
    Your Ad Here! Edneeis's Avatar
    Join Date
    Feb 2000
    Location
    Moreno Valley, CA (SoCal)
    Posts
    7,339
    If its a file DSN then you can just open it as text and find the path otherwise I don't know. If you can use the DSN without having the path then why do you need it?

  5. #5

    Thread Starter
    Frenzied Member maged's Avatar
    Join Date
    Nov 2002
    Location
    Egypt
    Posts
    1,040
    hi there,

    i am building a database class that uses oledbconnection to perform tons of common task in my software, i want to make this class as general as possible.

    i dont want to declare in it two types of conncetions

    (ODBC & OLEDB) and on every operation i should check who will work, i intend to make a single oledb connection that i should use with dsn , by knowing it's name and path.

    of course all the databases i intend to connect to is Access 2k , so there will never be a problem with ODBC, as i will always know what is the type of the database behind it.


    THX for you attention

    BST RGDS

  6. #6
    New Member
    Join Date
    Apr 2004
    Posts
    6
    Help!

    I downloaded and installed that package from

    http://www.microsoft.com/downloads/d...displaylang=en

    but nothing happened. My Visual Studio .NET doesn't understand ODBC. It just says: "Type 'OdbcConnection' is not defined". And naturally it doesn't understand my namespace either.

    What's wrong?

  7. #7
    Hyperactive Member
    Join Date
    Jun 2001
    Location
    Buffalo, NY
    Posts
    297
    Try the following:

    Code:
            Dim odcQuote As Odbc.OdbcConnection
            Dim odaQuote As Odbc.OdbcDataAdapter
    That works for me, but I've got .NET 2003

  8. #8
    Frenzied Member
    Join Date
    Aug 2000
    Posts
    1,539
    or search the registry (were the dsn is stored, extract it, and get ur path to the db from there)

    when i opened this thread i thought i would see a question that will take me weeks to figure out,
    please from now on title your messages approperiately according to what u need help with, u will get more responses.

  9. #9
    New Member
    Join Date
    Apr 2004
    Posts
    6
    Nothing helps. Or actually I didn't even understand what kovan wrote:
    "or search the registry (were the dsn is stored, extract it, and get ur path to the db from there)"
    'cause I'm such poor programmer and my english isn't that great either...

    I'm just wondering, if it installed into the right place. I didn't change anything in the wizard, so it installed it here:

    C:\Program Files\Microsoft.NET\Odbc.Net

    it made that Odbc.Net-file. I have also Microsoft Visual Studio .NET -file...

    Any ideas?

  10. #10
    Frenzied Member
    Join Date
    Aug 2000
    Posts
    1,539
    Originally posted by pupil
    Nothing helps. Or actually I didn't even understand what kovan wrote:
    "or search the registry (were the dsn is stored, extract it, and get ur path to the db from there)"
    'cause I'm such poor programmer and my english isn't that great either...

    I'm just wondering, if it installed into the right place. I didn't change anything in the wizard, so it installed it here:

    C:\Program Files\Microsoft.NET\Odbc.Net

    it made that Odbc.Net-file. I have also Microsoft Visual Studio .NET -file...

    Any ideas?
    lol
    all DSN connections one makes through data sources under Administrative Tools in control panel ARE stored in registry
    so what has to be done is, one must read the registry and the connection strings and all the properties are stored in registry for each DSN created.

    If that doesnt make any sense, then your an idiot.(one or to level lower than a poor programmer)

  11. #11
    Fanatic Member
    Join Date
    Oct 2001
    Location
    Three Anchor Bay, Cape Town, South Africa
    Posts
    769
    Hi Pupil,

    If you need to know details of any of the following steps just ask.

    1) Make sure that you have a reference to the System.Data component. If not, then reference it!
    2) Open the Object Browser and make sure you can see the System.Data.ODBC namespace. If not, then it is possible that there is a System.Data.ODBC component you need to reference. If there is, then reference it!
    3) Where you try to use the odbc objects, try using the fully qualified names (System.Data.ODBC.ODBCConnection).

    If none of these help, then I am not sure what the problem might be either.

    Kovan , this is a place where people get help. You dont have to put anyone down here, whatever questions they might ask.

  12. #12
    New Member
    Join Date
    Apr 2004
    Posts
    6
    Thanks shunt, but i decided to install Visual Studio 2003 to my computer, so that should solve the problem.

  13. #13

    Thread Starter
    Frenzied Member maged's Avatar
    Join Date
    Nov 2002
    Location
    Egypt
    Posts
    1,040
    thx kovan, can you explain in .net code how can i extract the dsn properties from the regestry,

    i have already sent you a pm , i hope you are not annoyed with my continous questiosn.

    thx

  14. #14
    Frenzied Member
    Join Date
    Aug 2000
    Posts
    1,539
    Originally posted by shunt

    Kovan , this is a place where people get help. You dont have to put anyone down here, whatever questions they might ask. [/B]
    I dont like being put down when i help someone, they should at least appreciate it,
    if they put me down i will put them down.

  15. #15
    Frenzied Member
    Join Date
    Aug 2000
    Posts
    1,539
    Originally posted by maged
    thx kovan, can you explain in .net code how can i extract the dsn properties from the regestry,

    i have already sent you a pm , i hope you are not annoyed with my continous questiosn.

    thx
    Reading registry
    VB Code:
    1. Imports Microsoft.Win32
    2.  
    3.     Public Function RegValue(ByVal Hive As RegistryHive, _
    4.        ByVal Key As String, ByVal ValueName As String, _
    5.        OptionalByRef ErrInfo As String = "") As String
    6.  
    7.       'DEMO USAGE
    8.  
    9.         'Dim sAns As String
    10.         'Dim sErr As String = ""
    11.  
    12.         'sAns = RegValue(RegistryHive.LocalMachine, _
    13.         '  "SOFTWARE\Microsoft\Windows\CurrentVersion", _
    14.         '  "ProgramFilesDir", sErr)
    15.         'If sAns <> "" Then
    16.         '    Debug.WriteLine("Value = " & sAns)
    17.         'Else
    18.         '    Debug.WriteLine("This error occurred: " & sErr)
    19.  
    20.         'End If
    21.  
    22.         Dim objParent As RegistryKey
    23.         Dim objSubkey As RegistryKey
    24.         Dim sAns As String
    25.         Select Case Hive
    26.             Case RegistryHive.ClassesRoot
    27.                 objParent = Registry.ClassesRoot
    28.             Case RegistryHive.CurrentConfig
    29.                 objParent = Registry.CurrentConfig
    30.             Case RegistryHive.CurrentUser
    31.                 objParent = Registry.CurrentUser
    32.             Case RegistryHive.DynData
    33.                 objParent = Registry.DynData
    34.             Case RegistryHive.LocalMachine
    35.                 objParent = Registry.LocalMachine
    36.             Case RegistryHive.PerformanceData
    37.                 objParent = Registry.PerformanceData
    38.             Case RegistryHive.Users
    39.                 objParent = Registry.Users
    40.  
    41.         End Select
    42.  
    43.         Try
    44.             objSubkey = objParent.OpenSubKey(Key)
    45.             'if can't be found, object is not initialized
    46.             If Not objSubkey Is Nothing Then
    47.                 sAns = (objSubkey.GetValue(ValueName))
    48.             End If
    49.  
    50.         Catch ex As Exception
    51.  
    52.             ErrInfo = ex.Message
    53.         Finally
    54.  
    55.             'if no error but value is empty, populate errinfo
    56.             If ErrInfo = "" And sAns = "" Then
    57.                 ErrInfo = _
    58.                    "No value found for requested registry key"
    59.             End If
    60.         End Try
    61.         Return sAns
    62.     End Function

    the keys in registry are stored in
    HKEY_CURRENT_USER\Software\ODBC\ODBC.INI
    as well as
    HKEY_LOCAL_MACHINE\SOFTWARE\ODBC\ODBC.INI

    with the above code you have to read these registry values (look through them and find what ur looking for)
    it will have all the data.
    i would first read a little on reading registry in .NET before going further because you will need to know basics of registry reading if u havent done it before like you mentioned in your PM
    hope that helps, if you have any other questions, just post them

  16. #16

    Thread Starter
    Frenzied Member maged's Avatar
    Join Date
    Nov 2002
    Location
    Egypt
    Posts
    1,040
    thx a million kovan, i will give it a try by myself.

    of course i will let you know the results.

    Again thank you very much for your kind help

    BST RGDS

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