CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2
  1. #1
    Join Date
    Jul 2009
    Posts
    1

    SqlServer connect string working in "connect.udl" but not in ADO

    Hi all.

    I am a beginner in ADO, and am trying to write a very basic program to connect to a sqlserver using ADO in C++. The sqlserver uses windows authentication.

    I have followed the internet steps to create "connect.udl". I have been able to create the connection string, and "Test Connection" works like a charm.

    Now, when I try to use this file in my ADO-C++ program in Visual Studio 2003, the error "This application has requested the Runtime to terminate it in an unusual way. Please contact the application's support team for more information." error is shown, just when the _ConnectionPtr tries to do a "open" on the database.

    Here is my code :::


    ///////////////////////////////////////////////// CODE - Begin ///////////////////////////////////////////
    #include<iostream>
    #import "c:\program files\common files\system\ado\msado15.dll" rename ("EOF","ADOEOF") no_namespace

    using namespace std;
    int main(int argc, char *argv[])
    {

    _ConnectionPtr connection;
    _CommandPtr pCommand;
    _ParameterPtr pParameter;
    _RecordsetPtr recordset;
    int iErrorCode;
    HRESULT hr;


    hr = connection.CreateInstance(__uuidof(Connection));
    if(hr)
    {
    cout << "Connection obtained" << "\n";
    }

    hr = recordset.CreateInstance(__uuidof(Recordset));
    if(hr)
    {
    cout << "RecordSet created" << "\n";
    }

    cout << "About to open connection" << "\n";

    connection->Open(L"File Name=E:\connect.udl;", L"", L"", adConnectUnspecified);

    cout << "open connection opened" << "\n";

    recordset->Close();
    }
    ///////////////////////////////////////////////// CODE - End ///////////////////////////////////////////






    The output is :::
    ///////////////////////////////////////////////// OUTPUT - Begin ///////////////////////////////////////////
    Connection obtained
    RecordSet created
    About to open connection

    This application has requested the Runtime to terminate it in an unusual way.
    Please contact the application's support team for more information.
    Press any key to continue
    ///////////////////////////////////////////////// OUTPUT - End ///////////////////////////////////////////


    I will be grateful of any enlightenment.

  2. #2
    Join Date
    Dec 2007
    Location
    South Africa
    Posts
    263

    Re: SqlServer connect string working in "connect.udl" but not in ADO

    When you post in a Forum please use the code tags that are provided so that someone who is interested in helping you can help or else noone will be interested in reading this messy code. i am C# developer. i have done C++ in my academic days. So i cant help. if only it was C# it was going to be better
    Few companies that installed computers to reduce the employment of clerks have realized their expectations.... They now need more and more expensive clerks even though they call them "Developers" or "Programmers."

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

Featured