Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Database connectivity using C/C++ 1

Status
Not open for further replies.

Valius

Programmer
Oct 20, 2000
174
US
I hope I can make sense here. I've been using the MSADO.dll to access a SQL server through ADO. That works fine, but I want to be able to do that differently without using MFC or anything like that. I guess I want to make my own class of DB connectivity and I was wondering how I could do that with out using any already made DLL's or MFC. Any help on how I could do this in raw C/C++ please let me know. Any good tutorials on this subject would be great also. Thanks in advance!

Niky Williams
NTS Marketing Inc.
 
This isn't the end all be all answer, but I know what you mean.

You might want to look for NTWDB.LIB and NTWDB.DLL in the MSDN Library.
It uses a direct (Non-ADO) connection to the database. I'm not sure how long support will be maintained as M$ is pushing OLE, ODBC, and ADO and whatever else they can. But the langauge is fairly simple. I used DBLIB (Sybase's equivalent) with no problems.
Its a bit like ADO, but doesn't have the overhead or as many things done for you (ie recordsets).
 
okay, I'll take a look at it...thank you for your input!

Niky Williams
NTS Marketing Inc.
 
This is a short sample on DB connection to SQLSercer and some short execution. I access there ADO through ATL.

#include <iostream.h>
#include<atlbase.h>
#include<adoint.h>
int main(int argc, char* argv[])
{
CoInitialize(0);
{
CComPtr<_Connection> pConn;
CComPtr<IUnknown> pUnk;
HRESULT hr=pConn.CoCreateInstance
(L&quot;ADODB.Connection&quot;,0,CLSCTX_INPROC_SERVER);
if(FAILED(hr))
{
cout<<&quot;failed&quot;<<endl;
}
hr=pConn->Open(
SysAllocString
(L&quot;driver={SQL Server};server={xxx};uid={sa};pwd={};source={GENTRAN};&quot;),
0,0,0);
if(FAILED(hr))
{
cout<<&quot;failed&quot;<<endl;
}
hr=pConn->Execute(
SysAllocString(L&quot;create table xxwwkkw(a integer)&quot;),
0,0,0);
if(FAILED(hr))
{
cout<<&quot;failed&quot;<<endl;
}
}
CoUninitialize();
return 0;
}
John Fill
1c.bmp


ivfmd@mail.md
 
Geez...looks pretty interesting to say the least. Thanks for the sample snippet. Haven't messed to much with templates...probably should learn about them. Thank you again, you have answered many of my qestions in the past and for that I am greatly appreciative!

Niky Williams
NTS Marketing Inc.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top