Click to See Complete Forum and Search --> : SqlServer connect string working in "connect.udl" but not in ADO


ajaygargqaz
July 7th, 2009, 08:01 AM
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.

vuyiswam
August 21st, 2009, 05:24 AM
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