all groups > sql server odbc > august 2004 >
You're in the

sql server odbc

group:

Connection to ODBC without a DSN


Connection to ODBC without a DSN Tony
8/27/2004 3:53:47 PM
sql server odbc:
Is it possible to connect to an ODBC driver (e.g. SQL Server or Oracle)
directly without having to create a DSN before hand.

This would be great as dumb users can't handle creating a DSN.
Would be nice if I could ask them SQL Server or Oracle, server name, user
name and password only and programmatically connect with that amount of
information.

Tony

Re: Connection to ODBC without a DSN Tony
8/27/2004 4:17:36 PM
Nope, not an option, would require a total recode of my database layer.
I'm required to continue using ODBC.
Application is C++/MFC client server application.

Thanks,
Tony

P.S. I have heard that OLEDB runs slightly slower due to COM marshaling.
What makes it a better choice from a C++ perspective?

[quoted text, click to view]

Re: Connection to ODBC without a DSN Aaron [SQL Server MVP]
8/27/2004 4:58:30 PM
You can use an OLEDB connection which is better anyway... see
http://www.aspfaq.com/2126 for samples that work in VB and ASP, and the
basic structure should work from any client language that supports it...

--
http://www.aspfaq.com/
(Reverse address to reply.)




[quoted text, click to view]

Re: Connection to ODBC without a DSN Sue Hoegemeier
8/29/2004 10:13:51 PM
You can use a dsn-less connection. Code the connection
string with the driver/provider you use in whatever syntax
is required for the data access api you are using with your
application.
OLE DB can provide more functionality and is generally
faster than ODBC.

-Sue

On Fri, 27 Aug 2004 16:17:36 -0500, "Tony"
[quoted text, click to view]
Re: Connection to ODBC without a DSN Brannon Jones
8/30/2004 11:04:08 AM
To be more specific, you use SQLDriverConnect instead of SQLConnect.

You can even leverage the driver to prompt for the login information.

Here's an example:

SQLCHAR* connectionString = (SQLCHAR*)"driver={SQL
Server};database=mydatabase";
SQLDriverConnect(hdbc, hwnd, connectionString, SQL_NTS, NULL, 0, NULL,
SQL_DRIVER_PROMPT);

SQL_DRIVER_PROMPT will cause the driver to display a dialog prompting the
user for the server name and uid/pwd information.

As far as ODBC vs. OLEDB is concerned, OLEDB is nice, it is a lot more
flexible than ODBC, but it's also a lot more difficult to use. If you're
accessing simple, relational data, just use ODBC. If you're already using
ODBC, and you dont need some specific feature of OLEDB, just continue to use
ODBC.

Brannon

[quoted text, click to view]
Re: Connection to ODBC without a DSN Tony
8/30/2004 6:26:13 PM
Thanks for the info.
I just need a way now to get the connection string used so I can save it for
next time.
Doesn't look like it gives it back to you.

Thanks,
Tony


[quoted text, click to view]

Re: Connection to ODBC without a DSN Brannon Jones
8/31/2004 2:50:22 PM
Why doesn't it look like it gives it back to you?

My example is a basic example of how to use SQLDriverConnect().

There are parameters on SQLDriverConnect() that return the connection string
that was used to connect.

Brannon

[quoted text, click to view]
Re: Connection to ODBC without a DSN Tony
9/1/2004 11:59:35 PM
I guess I have brain damage today, my apologies. :-)

Thanks for the reply,
Tony

[quoted text, click to view]

AddThis Social Bookmark Button