473,732 Members | 2,207 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 6094
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************* *@exisconsultin g.com

"Mike" <mi*******@hotm ail.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************* *@exisconsultin g.com

"Mike" <mi*******@hotm ail.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*******@hotm ail.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 ConnectionStrin g.

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.Configur ation; //for AppSettingsRead er
private string CreateConnStrin g(){
//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 = "connectionstri ng goes here";

AppSettingsRead er rdr = new AppSettingsRead er ();

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

//return the connectionstrin g template with the location of the
//database inserted at the right spot
return CONN_STRING.Rep lace ("VAL_TO_REPLAC E", strLocation);
}

Now you can use that connectionstrin g 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************* *@exisconsultin g.com

"Mike" <mi*******@hotm ail.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************* *@exisconsultin g.com

"Mike" <mi*******@hotm ail.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*******@hotm ail.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************* *@exisconsultin g.com

"Mike" <mi*******@hotm ail.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
6188
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 from the cli is for all intents practicaly instantaneous. After much research I discovered that PHP by default uses a dynamic cursor type which can be quite a bit slower than a forward only cursor. BTW I have been searching forward only/read...
6
18717
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
9636
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 work from
3
4158
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 information on this at all can anyone help please? nark
0
1638
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 text file. Can you any expert, give me ideas as to how to go about? I have used the following code for connection and connection is successful. I m able to insert records (i got the code from codeproject website). I was successfully able to insert...
2
3622
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 connection dialog should the user want to set up a server / database that is different than the default installation? Any help would be greatly appreciated.
4
3433
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 homepage. Also, when the user clicks on the description hyperlink they should see a dropdown with other hyperlinks such as hockey, baseball, etc. Here is what I have so far. I am new to asp and mysql, I would really appreciate the help. % ...
3
6267
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 Administrator. I uncommented the extension=php_ibm_db2.dll line in my php.ini file. <?php $DBName = "WSC520"; // The name of the database ...
1
2024
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 DBEngine(0) ..BeginTrans
0
8774
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9447
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
9235
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8186
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6735
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6031
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4550
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 last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4809
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
2721
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.