468,505 Members | 1,674 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,505 developers. It's quick & easy.

creating a dynamic ODBC connection in C#

I am writing a .NET application in C# that uses Crystal
Reports. I want the crystal reports to grab information
from a database no matter where the database is
located. To do this, I want to create an ODBC connection
to the database at runtime in order for the report to
grab data from the database. Does anyone have a code
snippet that shows how to do this? Thank you very much
for your reply.

Mike

ps. Is there anything else I can do instead of creating
a ODBC connection at runtime?
..
Nov 15 '05 #1
5 5760
Mike,

There really is nothing else you can do to create an ODBC connection.

If you want to create a dynamic connection to the database, you should
be able to construct a connection string (with the connection parameters
that are determined by your program), and then pass that to the ODBC
connection class.

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- ni**************@exisconsulting.com

"Mike" <mi*******@hotmail.com> wrote in message
news:06****************************@phx.gbl...
I am writing a .NET application in C# that uses Crystal
Reports. I want the crystal reports to grab information
from a database no matter where the database is
located. To do this, I want to create an ODBC connection
to the database at runtime in order for the report to
grab data from the database. Does anyone have a code
snippet that shows how to do this? Thank you very much
for your reply.

Mike

ps. Is there anything else I can do instead of creating
a ODBC connection at runtime?
.

Nov 15 '05 #2
Thanks for your quick reply. Can I do the same thing
(create a dynamic connection) using OLEDB instead. Which
is better? I'll be dealing with a few standard DBs such
as SQLServer, MySQL, and maybe Oracle.
-----Original Message-----
Mike,

There really is nothing else you can do to create an ODBC connection.
If you want to create a dynamic connection to the database, you shouldbe able to construct a connection string (with the connection parametersthat are determined by your program), and then pass that to the ODBCconnection class.

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- ni**************@exisconsulting.com

"Mike" <mi*******@hotmail.com> wrote in message
news:06****************************@phx.gbl...
I am writing a .NET application in C# that uses Crystal
Reports. I want the crystal reports to grab information from a database no matter where the database is
located. To do this, I want to create an ODBC connection to the database at runtime in order for the report to
grab data from the database. Does anyone have a code
snippet that shows how to do this? Thank you very much
for your reply.

Mike

ps. Is there anything else I can do instead of creating a ODBC connection at runtime?
.

.

Nov 15 '05 #3
On Tue, 2 Sep 2003 08:20:10 -0700, "Mike" <mi*******@hotmail.com>
wrote:
I am writing a .NET application in C# that uses Crystal
Reports. I want the crystal reports to grab information
from a database no matter where the database is
located. To do this, I want to create an ODBC connection
to the database at runtime in order for the report to
grab data from the database. Does anyone have a code
snippet that shows how to do this? Thank you very much
for your reply.


This site might be helpfull when creating the ConnectionString.

How do you plan on telling your application where the DB is? It needs
to know that sooner or later... Will this be in the config-file?

using System.Configuration; //for AppSettingsReader
private string CreateConnString(){
//in the connection string,make sure to use an easily traced value
//for the location of the data (e.g. VAL_TO_REPLACE)
const string CONN_STRING = "connectionstring goes here";

AppSettingsReader rdr = new AppSettingsReader ();

//take the key out of the app.config file ("appSettings" element)
//<appSettings>
// <add key="location" value="myServer.myDomain.countrycode" />
//</appSettings>
string strLocation = (string)rdr.GetValue ("location",
Type.GetType (System.String));

//return the connectionstring template with the location of the
//database inserted at the right spot
return CONN_STRING.Replace ("VAL_TO_REPLACE", strLocation);
}

Now you can use that connectionstring with the targetted platform
(OleDb, ODBC, Sql, Oracle, ...)

Does OleDb work with Crystal Reports?

--
NULL
Nov 15 '05 #4
Mike,

It all depends on what the underlying data source supports. Personally,
if there is a managed provider, then I would use that (for example, the
SqlConnection and related classes for SQL server). If you can't do that,
then I would prefer OLEDB over ODBC.
--
- Nicholas Paldino [.NET/C# MVP]
- ni**************@exisconsulting.com

"Mike" <mi*******@hotmail.com> wrote in message
news:07****************************@phx.gbl...
Thanks for your quick reply. Can I do the same thing
(create a dynamic connection) using OLEDB instead. Which
is better? I'll be dealing with a few standard DBs such
as SQLServer, MySQL, and maybe Oracle.
-----Original Message-----
Mike,

There really is nothing else you can do to create an

ODBC connection.

If you want to create a dynamic connection to the

database, you should
be able to construct a connection string (with the

connection parameters
that are determined by your program), and then pass that

to the ODBC
connection class.

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- ni**************@exisconsulting.com

"Mike" <mi*******@hotmail.com> wrote in message
news:06****************************@phx.gbl...
I am writing a .NET application in C# that uses Crystal
Reports. I want the crystal reports to grab information from a database no matter where the database is
located. To do this, I want to create an ODBC connection to the database at runtime in order for the report to
grab data from the database. Does anyone have a code
snippet that shows how to do this? Thank you very much
for your reply.

Mike

ps. Is there anything else I can do instead of creating a ODBC connection at runtime?
.

.

Nov 15 '05 #5
Somewhat off topic, but I found a really nice .net MySQL control at
http://crlab.com/mysqlnet/

--
Jay Douglas
Fort Collins, CO

"Mike" <mi*******@hotmail.com> wrote in message
news:07****************************@phx.gbl...
Thanks for your quick reply. Can I do the same thing
(create a dynamic connection) using OLEDB instead. Which
is better? I'll be dealing with a few standard DBs such
as SQLServer, MySQL, and maybe Oracle.
-----Original Message-----
Mike,

There really is nothing else you can do to create an

ODBC connection.

If you want to create a dynamic connection to the

database, you should
be able to construct a connection string (with the

connection parameters
that are determined by your program), and then pass that

to the ODBC
connection class.

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- ni**************@exisconsulting.com

"Mike" <mi*******@hotmail.com> wrote in message
news:06****************************@phx.gbl...
I am writing a .NET application in C# that uses Crystal
Reports. I want the crystal reports to grab information from a database no matter where the database is
located. To do this, I want to create an ODBC connection to the database at runtime in order for the report to
grab data from the database. Does anyone have a code
snippet that shows how to do this? Thank you very much
for your reply.

Mike

ps. Is there anything else I can do instead of creating a ODBC connection at runtime?
.

.

Nov 15 '05 #6

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

5 posts views Thread by Todd Huish | last post: by
6 posts views Thread by Andi Reisenhofer | last post: by
3 posts views Thread by nark | last post: by
reply views Thread by NPC403 | last post: by
3 posts views Thread by gieforce | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.