Wednesday, March 28, 2012

Linking a text file to SQL Server

Hi all.
I need to create a Linked Server in SQL 2000 to a text file. Importing the file is not an option. It has to be linked. I tried creating a ODBC link to it but I must be doing something wrong because it didn't work.
Please help.
Thanks,
ODanielsif you have sucessfully created the linkserver, you can use
EXEC sp_tables_ex <link server name> to query the tables (csv/txt files) of that link.

a sample query to retrive rows from a file can look like
select * from [txtLinkSrv].[d:\folder]..[File1.csv]

here "txtLinkSrv" is the link server name, "d:\folder" is the folder name that contains the files, "File1.csv" is the name of a csv file.|||Thanks upalsen.

Can this be used with a network path? Or does it have to be local?
I tried it and I keep getting:

Server: Msg 7399, Level 16, State 1, Line 1
OLE DB provider 'MSDASQL' reported an error.
[OLE/DB provider returned message: [Microsoft][ODBC Driver Manager] Driver's SQLSetConnectAttr failed]
[OLE/DB provider returned message: [Microsoft][ODBC Driver Manager] Driver's SQLSetConnectAttr failed]
[OLE/DB provider returned message: [Microsoft][ODBC Text Driver] '(unknown)' is not a valid path. Make sure that the path name is spelled correctly and that you are connected to the server on which the file resides.]
OLE DB error trace [OLE/DB Provider 'MSDASQL' IDBInitialize::Initialize returned 0x80004005: ].

No comments:

Post a Comment