Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

odbc connection string

Status
Not open for further replies.

breilly

Programmer
Nov 12, 2002
17
0
0
US
I am trying to access xfd files from a C# program. Does anyone know what the connection string is? Or better yet, if you have an C# example of the oledbconnection string value, it would make my life much easier.
 
Technically, an xfd file is simply a flat, text file. Are you trying to access the underlying Vision file(s)? Do you have AccuODBC?

Regards.

Glenn
 
I can access an excel spread sheet (on my hard drive) VIA a C# program by setting up a connection string, creating a connection object, opening the connection, creating a SQL command, etc.

C#
String sConnectionString
= “Provider=Microsoft.Jet.OLEDB.4.0;” +
“Data Source’” + (@C:/junk.xls”) + “;” +
“Extended Properties=Excel 9.0;”

String sSqyString = “select * from myrange1”.

EXCEL
Created a named range called myrange1 within the
junk.xls worksheet

I can also access a vision file thru EXCEL by installing the ACUODBC driver and defining a system dsn (xyzdata). (I have a xyzdata and xyxdata.xfd file on my hard drive.) Then in Excel, I do a data – get external data –select xyzdata from the new data base query drop down box and the connection completes (It launches the query wizard). I then can bounce thru the wizard and get the correct results

So, I am trying to do a hybrid of the above 2. I want to access the xyzdata from my C# program. I hope this clears up the confusion from my original post.
 
Go into the ODBC control panel applet and select the ODBC datasource. Turn on tracing, then go through the wizard, thereby tracing the connection and fetch of results. Then turn off the trace! [smile]

From the trace you might be able to discern the connection string required.

The general look of an ODBC connection string is:
Code:
DSN=xyzdata;UID=userid;PWD=password;
You may omit the UID and/or PWD parameters if you don't have user/password identification on the datasource (don't know anything about AcuODBC).

Tom Morrison
 
Breilly

The best way I know of creating a connection string is the following:
* On your desktop, create a brand new text file.
* Change the file extension to .udl
* double click on the file, and follow the guides to create a connection to the ODBC source you're interested in.
* When done, exit the wizard, and rename the file extension back to txt.
* Open the file in notepad, and there's your connection string. I don't think, though, that the wizard saves the connection password in the connection string. You'll probably have to add it yourself, and it's something like 'Pwd=1234567;'.

Hope this helps.
.DaviD.
 
The simplest way is to manually create the DSN connection on the ODBC manager, and then in your C# application do the next...

string connectionString = "DSN=YOUR_DSN_NAME_HERE";

OdbcConnection dbcon;
dbcon = new OdbcConnection(connectionString);
dbcon.Open();
string sql = "SELECT * FROM TABLE";

OdbcCommand odbcomm = dbcon.CreateCommand();
odbcomm.CommandText = sql;
OdbcDataReader reader = odbcomm.ExecuteReader();

I hope you know what to do next with your reader ;)

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top