Sunday, February 19, 2012

How to access to database with c# using DSN

Hello, im new in c# language.

Can someone show me, step by step(with simples code) how can i connect to a DSN connection that aconfigure in my odbc connection in my machine, to connect to mydatabase ?

I need only a simple class that use a DSN connection to retreive information from the database.

Best regards

You don't want to use a System DSN. A System DSN uses ODBC which is a wrapper for OLE DB, meaning that you're talking about a lot of unnecessary overhead. The .Net System.Data.SqlClient classes talk directly to the SQL Server, without having to use OLE DB OR ODBC. Instead, you need to figure out how to build your Connection correctly.

TryConnectionStrings.com.

|||

Im not use SQL server, my database is db2 in AS/400.

Do u know how to connect directly to an as/400 database ?

|||

Hi,

From you description, it seems that you want to connect to your DB2 database by using DSN, right?

I suggest that you can try DB2OdbcFileConnectionString class which describes a DB2 ODBC file connection string.

To create a DSN file and associated connection string

Call the constructor for DB2OdbcFileConnectionString, DB2OdbcSysConnectionString, or DB2OdbcUserConnectionString.
Calling the constructor creates a connection string with default settings. These default settings can be set only through the Data Access Tool user interface.

If you use a file path for a file that currently exists, the system loads the connection string information in that file instead.

Fill in the relevant connection string properties with a call to the properties of the object created.
You can also fill in the connection string with GetString, which returns the connection string as a text string. Once you finish modifying the relevant values, you can return the connection string to the object with a call to SetString.

Save the connection string information back into storage with a call to Save.

For more information, see:
http://msdn2.microsoft.com/en-us/library/ms945575.aspx

Thanks.

No comments:

Post a Comment