Quote Originally Posted by chapran View Post
Driver={SQL Server Native Client 10.0};Server=(local);Database=FnsNew;Trusted_Connection=yes;
And I always got wrong result.
After you asked about connection string I decided to switch to production database just to test the code I've got from Schmidt. The connection string is:
DRIVER=SQL Server;SERVER=SRSNJC;UID=coordin;DATABASE=FnsNew;pwd=coordec

What's wrong with my connection to local server?
First of all, what you're currently using (ConnectionString-wise) is an unnecessary indirection (in both your Cnn-Strings).

ADO (a COM-lib) is meant to talk (directly) with other COM-libs (OleDB-Providers) -
but what you're using is ODBC-Drivers instead (which is IMO one unnecessary indirection too many).

Connection-Strings which contain "Driver=" are usually ODBC (with an often omitted, and leading
Connection-String-snippet -> Provider=MSDASQL.1; that gets automatically enhanced under the covers).

So, both your (ODBC-demanding) Cnn-Strings will ensure a Queue like the following:
[ADO] <-> [Generic OleDB-Provider for ODBC] <-> [specific ODBC-Driver]

If you want to avoid that, ensure that your Cnn-String does not contain the "Driver=" specifier,
but starts with a concrete "Provider=" term (leaving the generic ODBC-Mapper out of the loop):
[ADO] <-> [specific OleDB-Provider]

In my example I've used (a kind of old, "traditional" notation):
"Provider=SQLOleDB.1;...

But specific OleDB-Providers for MS-SQLServers "Native-Clients" (10 and 11) also exist -
and I've just tested my example successfully with e.g.:
"Provider=SQLNCLI10;

Olaf