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!

How do i connect remote sql server no use odbc.....(use Visual C++ )

Status
Not open for further replies.

cibrran

Programmer
Feb 24, 2001
77
CA
Help me dear my friends!


I wann'a that connect remote sql server no using ODBC!


Let's read above this



typically we used like that just next line

(Source Start....)
CDatabase db;
db.OpenEx( _T( "DSN=DBName" );
(Source End......)

but if use like just before way....

we must be setting [ODBC] => [sql] => [Server name,

certificate password]

every Install time You'll set your client's ODBC setting


then... I'll Let explain you that just I wann'a issue!

How do i connect remote sql server no use odbc?

like ( no using ODBC setting)

(Source Start....)
CDatabase db;
db.OpenEx( _T( "DSN=Server Address, ID='sa', password=''" );
(Source End......)

this way...


please help me....

I wann'a some your nice help and pretty advice and a little

words!


have a nice day....
 
Here is how I did it....I used ADO for it. When you first start off your program, you have to import a dll into your program like so:

#import "C:\Program Files\Common Files\System\ADO\msado15.dll" no_namespace rename("EOF", "EndOfFile")

The reason I renamed EOF to EndOfFile is so it doesn't get confused with other EOF statements. This will allow you to do the next thing.....

_ConnectionPtr SQLConn; //Declare a connection pointer
_CommandPtr SQLCommand; //So you can do stuff to the DB
_RecordsetPtr SQLRecord; //holds recordsets from the DB

now, here comes the fun part.

First you gotta initialize some stuff by doing this...

::CoInitialize(NULL);

Then you gotta create all the instances of your objects like so:

SQLConn.CreateInstance(__uuidof(Connection));
SQLConn->Open(&quot;Provider=sqloledb;Data Source=<YOUR SERVER>;Initial Catalog=<YOUR CATALOG>;User Id=sa;Password=;&quot;, &quot;&quot;, &quot;&quot;, adConnectUnspecified);

SQLCommand.CreateInstance(__uuidof(Command));
//VERY IMPORTANT
SQLCommand->ActiveConnection = SQLConn;

SQLRecord.CreateInstance(__uuidof(Recordset));

//For all the adxxxx keywords, you may wanna look them up
//in the VC++ help to know more about them
SQLRecord->Open(<TABLE NAME>, <CONN STRING FROM ABOVE>, adOpenKeyset, adLockOptimistic, adCmdTable);

Now that you have everything open...you set up a SQL command and execute it and stick it in a recordset like this:

SQLCommand->CommandText = &quot;SELECT * FROM <TABLE>&quot;;
SQLRecord = SQLCommand->Execute(NULL, NULL, adCmdText);

Then you can browse through your new recordset like this....
SQLRecord->MoveFirst();
SQLRecord->Fields->Item[<COLUMN IN YOUR TABLE>]->Value;

You can use functions on your SQLRecord such as:
MoveFirst();
MoveLast();
MoveNext();
Move(<RECORD #>)

The MSDN has a LOT of stuff on it...this is just the surface. Take a look at MSDN and see if you can get more info on it. Hope this helps you out!

Niky Williams
NTS Marketing




 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top