Sunday, March 11, 2012

Bulk Insert From Client PC

Hi everyone,
I'm having problems with this and hoped you might be able to help. I am
trying a bulk insert of a CSV file to sql server. No problems there,
however, the application i am writing is web based (asp.net), so a
client may upload a CSV from their local PC to a web server. I then need
to upload from the web server to the sql server (a seperate box
entirely). Is there any way of bulk inserting from a remote PC? I've
been looking at this method, or even an api that might do this?
Thank you in advanceYou can use DTS to pull the .CSV file into your SQL Server from your
Web Server or Remote PC? Failing that, can also use BCP (command line
option that supports BULK INSERT's). DTS may be preferable, if it's
regular operation yo ucan set up a SQL Agent Job to carry it out
automatically.
Regards
ALI
Francis wrote:
> Hi everyone,
> I'm having problems with this and hoped you might be able to help. I am
> trying a bulk insert of a CSV file to sql server. No problems there,
> however, the application i am writing is web based (asp.net), so a
> client may upload a CSV from their local PC to a web server. I then need
> to upload from the web server to the sql server (a seperate box
> entirely). Is there any way of bulk inserting from a remote PC? I've
> been looking at this method, or even an api that might do this?
> Thank you in advance|||You can use the BULK INSERT T-SQL command. If the file to be uploaded is in
a share on the web server, you can reference that file in the BULK INSERT
command using a UNC. For example
BULK INSERT <table> FROM '\\WEBSERVER\SHARE\filetobeuploaded.csv' ...
SQL/Server will have to be running under an account that has read access to
the share.
HTH,
Mike
"Francis" <f@.f.com> wrote in message
news:epmT1iBbFHA.2756@.tk2msftngp13.phx.gbl...
> Hi everyone,
> I'm having problems with this and hoped you might be able to help. I am
> trying a bulk insert of a CSV file to sql server. No problems there,
> however, the application i am writing is web based (asp.net), so a client
> may upload a CSV from their local PC to a web server. I then need to
> upload from the web server to the sql server (a seperate box entirely). Is
> there any way of bulk inserting from a remote PC? I've been looking at
> this method, or even an api that might do this?
> Thank you in advance
>|||Thanks guys,
I decided to use another method, using the SQLDMO COM object. My code
is as follows in c#, just in case someone has the same problem:
SQLServer server = new SQLServerClass();
_BulkCopy bcp = new BulkCopyClass();
_Database db = new DatabaseClass();
_Table table = new TableClass();
server.EnableBcp = true;
server.Connect( "server" , "user" , "password" );
bcp.DataFilePath = Server.MapPath( "files/data.csv" );
bcp.DataFileType =
SQLDMO_DATAFILE_TYPE.SQLDMODataFile_CommaDelimitedChar;
//bcp.FormatFilePath = @."C:\data.fmt";
bcp.RowDelimiter = @."\n";
bcp.UseExistingConnection = true;
bcp.MaximumErrorsBeforeAbort = 1000;
bcp.UseBulkCopyOption = true;
bcp.IncludeIdentityValues = true;
bcp.UseServerSideBCP = false;
table = server.Databases.Item( "Databasename" , "dbo"
).Tables.Item( "table" , "dbo" );
table.BeginAlter();
table.ImportData( bcp );
//table.DoAlter();
Michael Abraham wrote:
> You can use the BULK INSERT T-SQL command. If the file to be uploaded is
in
> a share on the web server, you can reference that file in the BULK INSERT
> command using a UNC. For example
> BULK INSERT <table> FROM '\\WEBSERVER\SHARE\filetobeuploaded.csv' ...
> SQL/Server will have to be running under an account that has read access t
o
> the share.
> HTH,
> Mike
> "Francis" <f@.f.com> wrote in message
> news:epmT1iBbFHA.2756@.tk2msftngp13.phx.gbl...
>
>

No comments:

Post a Comment