.txt to SQL Server import without using bulk
I am using Visual Studio 2010. My database is SQL Server. I have a static link which has daily updated data in .txt format (it is a tab (space) separated file). I want to import the data from the .txt file to the SQL Server database. This is to be done daily. Hence I can schedule it on the SQL Server to run everyday. The scheduling is done.
Can someone please he开发者_JS百科lp me to write the script for the import? And I can't use BULK command. Is there anyway to do this? Please help.
Thanks.
If you cannot use the BULK INSERT
statements (again: why??), then my best bet would be to create a small console app that would
download that file from the static URL
use the FileHelpers library to load the
.txt
file into memory (it does this very well and very easily - you define the structure as a C# class, and don't have to worry about anything else anymore...)use a SQL Server stored procedure or a parametrized SQL inline query to store the entries - one by one - into your SQL Server table
Once you have that console app, use the Windows scheduled tasks facility to run this app once e.g. every morning or whatever your schedule is.
You could use a scripting language like Groovy or Python to make the task easier and then just throw it in a task scheduler.
精彩评论