473,507 Members | 5,257 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 6077
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
6162
by: Todd Huish | last post by:
I have noticed something disturbing when retrieving datasets over a relatively slow line (multiple T1). I am looking at about 25 seconds to retrieve 500 rows via a php-odbc link. This same select...
6
18705
by: Andi Reisenhofer | last post by:
Hallo C# folks, Somebody know how to create a ODBC DSN dynamically in c# program. Also interesting for me would be the connectionstring for an Access Database. Thinks a lot Andreas
8
9609
by: Greg Strong | last post by:
Hello All, The short questions are 1 Do you know how to make DSN connection close in Access to Oracle 10g Express Edition? &/or 2 Do you know how to make a DSN-less pass-through query...
3
4142
by: nark | last post by:
I just downloaded ODBC drivers from the mySQL web site but whenever I try to create a DSN I get a system 1157 error The driver does show up ok in the windows control panel I cant find any...
0
1631
by: padhuwork | last post by:
Hi, I want to create a Windows DLL using VC++ 6.0 which connects to SQL Server. After establishing the connection, I want to retrieve records from table (query) and out put the recordset to a...
2
3606
by: Rico | last post by:
Hello, Can anyone tell me, is there an easy way to 1) Check to see if a DSN already exists and if not, create a system DSN for the back end? Also, is there an easy way to use the SQL Server...
4
3421
by: mramsay | last post by:
Hi, I'm having a real problem creating a dynamic hyperlink for my website. I want to pull the field name from mysql table. Field name is description. I would like this to be a hyperlink on my...
3
6231
by: Harmony504 | last post by:
HELP! Setup: PHP5.2.5, IIS 5.1, XP, AS/400 (DB/400 or DB2) I am trying to connect to a DB2 database from my computer. I installed DB2 Connect and set up the ODBC Driver in the Data Source...
1
2017
by: lyle fairfield | last post by:
By "dynamic" I mean the use of an SQL string in code. This is my best to date: I do not use ODBC frequently. Is there a simpler way? Public Sub Whatever() Dim q As DAO.QueryDef With...
0
7313
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7372
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
7481
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5619
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
5039
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
4702
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3190
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
1
758
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
411
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.