473,397 Members | 1,950 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,397 software developers and data experts.

Automate Importing File

Hello,

I need to automate importation of a excel file into a table. Here's my
scenario: I'm writing an ASP.NET application where users can pull reports on
imported data. The imported data is pulled from an old UNIX based system,
then converted to Excel. I want the user to be able to use the web app to
select and upload the file to the server, then press a button to have the
SQL server process the Excel file and import it. I know I can do this all in
ASP.NET: open excel file and append records to the table, but this can't be
optimal. The Excel file will be in the same format each time so columns and
such will be the same for each import.

Can you provide me some feedback or link to some resources.

Thanks!

David Lozzi
Nov 19 '05 #1
11 1860
You could write a DTS package to import the data and then invoke that
through DMO.

Based on many past experiences I have to say that Excel is just about
the worst possible format to choose for data interchange. Especially so
if manual intervention by users is involved. There are lots of problems
inherent in the formatting, undefined datatypes and lack of validation
that are implied by the spreadsheet format. If you have a Unix source
that you can import to Excel then that may well be a better place to
source the data for your database.

--
David Portas
SQL Server MVP
--

Nov 19 '05 #2
Before it reaches Excel its in a tab delimited text file. WOuld this be
happier?

Also, how do I write what I need. I need a little guidence on the
development of the import. Any references?

--
David Lozzi
Web Applications Developer
dlozzi@(remove-this)delphi-ts.com

"David Portas" <RE****************************@acm.org> wrote in message
news:11**********************@f14g2000cwb.googlegr oups.com...
You could write a DTS package to import the data and then invoke that
through DMO.

Based on many past experiences I have to say that Excel is just about
the worst possible format to choose for data interchange. Especially so
if manual intervention by users is involved. There are lots of problems
inherent in the formatting, undefined datatypes and lack of validation
that are implied by the spreadsheet format. If you have a Unix source
that you can import to Excel then that may well be a better place to
source the data for your database.

--
David Portas
SQL Server MVP
--

Nov 19 '05 #3
Integration services package job (with tasks) would seem to be your friend
here.

--
William Stacey [MVP]

"David Lozzi" <dl****@nospam.nospam> wrote in message
news:Oj**************@TK2MSFTNGP12.phx.gbl...
Hello,

I need to automate importation of a excel file into a table. Here's my
scenario: I'm writing an ASP.NET application where users can pull reports
on imported data. The imported data is pulled from an old UNIX based
system, then converted to Excel. I want the user to be able to use the web
app to select and upload the file to the server, then press a button to
have the SQL server process the Excel file and import it. I know I can do
this all in ASP.NET: open excel file and append records to the table, but
this can't be optimal. The Excel file will be in the same format each time
so columns and such will be the same for each import.

Can you provide me some feedback or link to some resources.

Thanks!

David Lozzi

Nov 19 '05 #4
OK, I made the package and it runs great when manually ran. how do I run it
from my web app? I'm using ASP.Net.

Thanks,

David
"William Stacey [MVP]" <wi************@gmail.com> wrote in message
news:u5**************@TK2MSFTNGP12.phx.gbl...
Integration services package job (with tasks) would seem to be your friend
here.

--
William Stacey [MVP]

"David Lozzi" <dl****@nospam.nospam> wrote in message
news:Oj**************@TK2MSFTNGP12.phx.gbl...
Hello,

I need to automate importation of a excel file into a table. Here's my
scenario: I'm writing an ASP.NET application where users can pull reports
on imported data. The imported data is pulled from an old UNIX based
system, then converted to Excel. I want the user to be able to use the
web app to select and upload the file to the server, then press a button
to have the SQL server process the Excel file and import it. I know I can
do this all in ASP.NET: open excel file and append records to the table,
but this can't be optimal. The Excel file will be in the same format each
time so columns and such will be the same for each import.

Can you provide me some feedback or link to some resources.

Thanks!

David Lozzi


Nov 19 '05 #5
A delimited file is certainly easier to import. You can load it with a
single BULK INSERT - see Books Online for details of that command.
Obviously you need to be sure that you will never have TABs in the data
between the delimiters.

--
David Portas
SQL Server MVP
--

Nov 19 '05 #6
OK, I made the package and it runs great when manually ran. how do I run it
from my web app? I'm using ASP.Net.

Thanks,

David
"David Portas" <RE****************************@acm.org> wrote in message
news:11*********************@f14g2000cwb.googlegro ups.com...
A delimited file is certainly easier to import. You can load it with a
single BULK INSERT - see Books Online for details of that command.
Obviously you need to be sure that you will never have TABs in the data
between the delimiters.

--
David Portas
SQL Server MVP
--

Nov 19 '05 #7
In SQL Server 2000 you'll have to use COM to create the SQLDMO Package
Object. Run it with the Execute Method.

Books Online is your friend. It documents the details of all this. If
you don't have BOL you can find it at:
http://msdn.microsoft.com/library/de...asp?frame=true

--
David Portas
SQL Server MVP
--

Nov 19 '05 #8
Yes, I have and am using the SQL Books Online...

When searching for these items, I just get more confused. Would BULK_INSERT
be easier? You simply say "use COM to create the SQLDMO Package Object. Run
it with the Execute Method." I have no idea what you mean. Sad, I know, but
I'm trying here. Can you go into a little more detail?

Thanks,
"David Portas" <RE****************************@acm.org> wrote in message
news:11*********************@g47g2000cwa.googlegro ups.com...
In SQL Server 2000 you'll have to use COM to create the SQLDMO Package
Object. Run it with the Execute Method.

Books Online is your friend. It documents the details of all this. If
you don't have BOL you can find it at:
http://msdn.microsoft.com/library/de...asp?frame=true

--
David Portas
SQL Server MVP
--

Nov 19 '05 #9
1) BULK INSERT. Here's an example of how to insert to a table from a
TAB delimited file using T-SQL. You can obviously execute this proc
using the ADO Command Object. Always load to a view rather than a table
otherwise the load will break if you add new columns to the table.

CREATE PROC dbo.usp_load
AS

DECLARE @error INTEGER

BULK INSERT dbo.some_view
FROM 'd:\path\your_file.txt'
WITH
(
FIELDTERMINATOR = '\t',
ROWTERMINATOR = '\n'
)

SET @error = @@ERROR
/* error handling goes here */

RETURN @error

GO

To create the view used in this example (at design-time rather than
run-time):

CREATE VIEW dbo.some_view
AS
SELECT col1, col2, col3, ...
FROM your_table

2) The above won't do for an Excel file - you'll have to run a DTS
package for that. The DTS object model is a COM API - not .NET. There
are various examples in the following article showing the different
ways to call a DTS package: C#, VB, ASP, command line, etc:

http://www.sqldts.com/default.aspx?104

--
David Portas
SQL Server MVP
--

Nov 19 '05 #10
Ah #2 helped a lot. I'm now getting

Step "DTSStep_DTSDataPumpTask_1" Failed
Error: -2147467259
Source: Microsoft Data Transformation Services Flat File Rowset Provider
Description: Error opening datafile: Logon failure: unknown user name or bad
password.

If you happen to know exactly the solution, please let me know. otherwise I
think I can handle it.

Thanks a lot for you help!
David

<RE****************************@acm.org> wrote in message
news:11**********************@g14g2000cwa.googlegr oups.com...
1) BULK INSERT. Here's an example of how to insert to a table from a
TAB delimited file using T-SQL. You can obviously execute this proc
using the ADO Command Object. Always load to a view rather than a table
otherwise the load will break if you add new columns to the table.

CREATE PROC dbo.usp_load
AS

DECLARE @error INTEGER

BULK INSERT dbo.some_view
FROM 'd:\path\your_file.txt'
WITH
(
FIELDTERMINATOR = '\t',
ROWTERMINATOR = '\n'
)

SET @error = @@ERROR
/* error handling goes here */

RETURN @error

GO

To create the view used in this example (at design-time rather than
run-time):

CREATE VIEW dbo.some_view
AS
SELECT col1, col2, col3, ...
FROM your_table

2) The above won't do for an Excel file - you'll have to run a DTS
package for that. The DTS object model is a COM API - not .NET. There
are various examples in the following article showing the different
ways to call a DTS package: C#, VB, ASP, command line, etc:

http://www.sqldts.com/default.aspx?104

--
David Portas
SQL Server MVP
--

Nov 19 '05 #11
I think you can create a stored procedure to run DTS and call the sp from
asp.net

CREATE PROCEDURE pr_import_data
AS
exec master..xp_cmdshell 'dtsrun /Sserver_name /Uuser_nName
/Ppassword /Npackage_name'
GO

For Syntax
http://msdn.microsoft.com/library/de...tsrun_95kp.asp


"David Lozzi" wrote:
OK, I made the package and it runs great when manually ran. how do I run it
from my web app? I'm using ASP.Net.

Thanks,

David
"William Stacey [MVP]" <wi************@gmail.com> wrote in message
news:u5**************@TK2MSFTNGP12.phx.gbl...
Integration services package job (with tasks) would seem to be your friend
here.

--
William Stacey [MVP]

"David Lozzi" <dl****@nospam.nospam> wrote in message
news:Oj**************@TK2MSFTNGP12.phx.gbl...
Hello,

I need to automate importation of a excel file into a table. Here's my
scenario: I'm writing an ASP.NET application where users can pull reports
on imported data. The imported data is pulled from an old UNIX based
system, then converted to Excel. I want the user to be able to use the
web app to select and upload the file to the server, then press a button
to have the SQL server process the Excel file and import it. I know I can
do this all in ASP.NET: open excel file and append records to the table,
but this can't be optimal. The Excel file will be in the same format each
time so columns and such will be the same for each import.

Can you provide me some feedback or link to some resources.

Thanks!

David Lozzi



Nov 19 '05 #12

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

11
by: Jeff Wagner | last post by:
I am importing a file which contains a persons name (firstName, middleName, etc). If I define a function to do this, how can I use the variables outside of that function? Here is the code: ...
12
by: qwweeeit | last post by:
The pythonic way of programming requires, as far as I know, to spread a big application in plenty of more manageable scripts, using import or from ... import to connect the various modules. In...
11
by: Grim Reaper | last post by:
I am importing a .csv file into Access that has 37 fields. My problem is that sometimes the last field only has data at the end of the column (it looks like when you import a file into Access, for...
1
by: sparks | last post by:
I have never done this and wanted to ask people who have what is the best way. One person said import it to excel, then import it into access table. but since this will be done a lot, I am...
16
by: cyranoVR | last post by:
This is the approach I used to automate printing of Microsoft Access reports to PDF format i.e. unattended and without annoying "Save As..." dialogs, and - more importantly - without having to use...
1
by: Mark | last post by:
Hi all, I have a Access 2002 FE/BE scenario where the BE is stored on a network drive. Due to the amount of importing/deleting, the database bloats quite a lot. UP until now, I have been booting...
3
by: John Marble | last post by:
I have around 400 excel files filled with data that I need to import in ACCESS. The tricky part is that they must be imported one at time, and properly corrected before importing the next one. I...
10
by: Killer42 | last post by:
Hi all. If necessary I'll repost this in the Windows forum, but I thought this would be a good place to hit a fair cross-section of the community. Besides, anyone can see that all the best brains...
12
by: JMO | last post by:
I can import a csv file with no problem. I can also add columns to the datagrid upon import. I want to be able to start importing at the 3rd row. This will pick up the headers necessary for the...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.