creating a dynamic ODBC connection in C#

M

Mike

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?
..
 
N

Nicholas Paldino [.NET/C# MVP]

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.
 
M

Mike

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]
- (e-mail address removed)

Mike said:
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?
.


.
 
N

Nicholas Paldino [.NET/C# MVP]

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]
- (e-mail address removed)

Mike said:
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]
- (e-mail address removed)

Mike said:
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?
.


.
 
N

NULL

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?
 
J

Jay Douglas

Somewhat off topic, but I found a really nice .net MySQL control at
http://crlab.com/mysqlnet/

--
Jay Douglas
Fort Collins, CO



Mike said:
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]
- (e-mail address removed)

Mike said:
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?
.


.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top