|
Question : .CSV to Database with ODBC connection.
|
|
I am trying to create a ODBC connection to a CSV file with the following code:
string CSVFolderPath = "c:\\CSAMS\\baudtest.csv"; string ConnectionString = "Driver={Microsoft Text Driver (*.txt;*.csv)};Dbq=" + CSVFolderPath.Trim() + ";Extensions=asc,csv,tab,txt" + ";Persist Security Info=False"; OdbcConnection connection = new OdbcConnection(ConnectionString); connection.Open();
The last line run time error's with the following error message
ERROR [IM002] [Microsoft][ODBC Driver Manager] Data source name not found and no default driver specified.
The Value of the connection string is: "Driver={Microsoft Text Driver (*.txt;*.csv)};Dbq=c:\\CSAMS\\baudtest.csv;Extensions=asc,csv,tab,txt;Persist Security Info=False"
and the CSV comma delimeted text file is located in c:\CSAMS\baudtest.csv so there is no problem with the path. I have used it successfulle in VS 2003. Is this maybe a 2005 thing?
|
|
Answer : .CSV to Database with ODBC connection.
|
|
You ll have to use a different driver to connect to csv file.
This is new command :
select * from OpenRowset('MSDASQL','Driver={Microsoft Text Driver (*.txt; *.csv)}; DefaultDir=C:\Temp;Extended properties=''ColNameHeader=True;Format=CSVDelimited;''','select * from Test.csv')
If you want more formating you ll need to use a schema.ini file
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/odbc/htm/odbcjetschema_ini_file.asp
|
|
|
|