Open DB of an Linked Server with C++

  • Hi people!

    I'm new here and have following problem:

    my C++ application uses Access2003 DBs and therefore I use the CDatabase class to open the DB and to work with it

    db.OpenEx( _T("DRIVER=Microsoft Access Driver (*.mdb) ;DBQ=") + pfad_db + _T(";FIL=MS Access"), CDatabase::noOdbcDialog | CDatabase::useCursorLib);

    this part works fine.

    If I import my Access DB in SQL Server 2005 I also can open the DB in this way:

    db.OpenEx(_T("DRIVER={"SQL Native Client"};Server=(local);APP=Microsoft\x00ae Visual Studio\x00ae 2005;WSID=")

    + Name_SQL_Server + _T(";DATABASE=") + name_db +_T(";Trusted_Connection=Yes"),

    CDatabase::noOdbcDialog | CDatabase::useCursorLib);

    But my wish is not to import the Access DB, but to use it as a Linked Server in SQL Server. So I created a Linked Server and also can work with it in the Management Studio. (E.g. I get all the data with SELECT * FROM [LinkedServer]...[Table])

    The problem now is how to open the LinkedServer DB from my C++ code?

    What is the right Name_SQL_Server now? And what is the name of db? Because there is only the Linked Server and the names of tables, no catalog or db name (see --> [LinkedServer]...[Table]).

    Has somebody experience in this way?

  • I see two options for this:

    1. Continue to have the C++ application connect to it directly, without going through SQL.

    2. Create a database on the SQL server, and connect to that database from C++, and then query that database using the usual linked server syntax (4-part names).

    I'm not sure why you'd want to connect that second way, but it seems to be what you're getting at, and I'm assuming you have a good reason for it.

    - Gus "GSquared", RSVP, OODA, MAP, NMVP, FAQ, SAT, SQL, DNA, RNA, UOI, IOU, AM, PM, AD, BC, BCE, USA, UN, CF, ROFL, LOL, ETC
    Property of The Thread

    "Nobody knows the age of the human race, but everyone agrees it's old enough to know better." - Anon

Viewing 2 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic. Login to reply