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 Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

A Text File, C# 2008 and SQL Server 2005 Express

Status
Not open for further replies.

rdrunner400

Programmer
Feb 12, 2007
17
GB
Hi,

As you can see from the subject line I am wanting to do the above ... which is import a flat text file into SQL 2005 Express using c# 2008.

I am new to this as we are upgrading from a FOXPRO environment to .net

I have a button on a form which on the click event i have a dialog box that opens and i am able to select a text file, BTW this text file is delimited with a Tab and has around 100,000 records in and in each row there is 130 fields all text with average field lengths of varchar(50). This process will be repeated weekly.

Now i can get the Text file into my SQL DB using Bulk Insert fine.

BUT that is not how it is to be done. NO SIR !!!

I am wanting to just make it so that a form will load and it will load into the SQL nice and easy.

Now i have gone around the net looking for a simple way to import this file..... but its not to be easy....

I know i can use BULK insert or DTS but that is not to be used.... BOTH work fine ... but it needs to run from the click event of the button. I don't want the user to have any access to SQL Server what so ever.

I have succesfully created a connection to the data base.

My DataBase is called TESTDB and the Table name is called TEST_TABLE and i have created the table from the specification given. 130 Text Fields !!! OH !!!!

THE only thing i cannot do is to import the records easily into it..... using code ???

IS there a simple way to do this ?????? Can i connect to the DB and run a stored procedure possibly that i could place the BULK INSERT code in and pass a parameter to the stored procedure stating where to find the file on the server as it will be in different places as each week?

This has been driving me mad for a while ... and i would have thought it would be easy to do as it was in fox alas it is not :(

Regards,

Murray
 
Murry,
Get a small sample working.
There are several drastically different approaches to this.

DB Security:
You can connect using a database user account. Then your application can connect with that account.

File Processing:
You can either create a stored procedure, with 130 parameters and call that.
Another option is to add a DBML to your project. This requires at least .Net 3.5
Using LINQ is nicer, and gives you a class to work with.

I advise you NOT do dynamic SQL generation and just run the string. This opens you up to attacks you can't even think of.

Lodlaiden

You've got questions and source code. We want both!
Oh? That? That's not an important password. - IT Security Admin (pw on whiteboard)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top