Click here to Skip to main content
15,886,199 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
i have C# WinForm program that i need to insert fast big data to sql-server.

The sql-server is in cloude server, and the file that i load in local computer.

the file is Text (Tab delimited) in

d:\TEST\TEST.txt and has Full permissions

BAR    DES     MAK
111    aaa     222
333    bbb     333
.
.

the sql-server table is CatTbl:

SQL
BAR nvarchar(250)
DES nvarchar(250)
MAK nvarchar(250)

i try to insert like this:

C#
SQL = @"BULK INSERT CatTbl FROM 'd:\TEST\TEST.txt' WITH (CODEPAGE=1255,FIELDTERMINATOR = '\t')";
Cmd = new SqlCommand(SQL, Conn);
Cmd.ExecuteNonQuery();
Cmd.Dispose();

when i work on local sql-server its works excellent.

but in cloude sql-server i got error:

Cannot bulk load because the file "d:\TEST\TEST.txt" could not be opened. Operating system error code 21(The device is not ready.).
Please note that the sql-server connection is successful
I searched the web and found no answer that solved the problem. I would appreciate some help

What I have tried:

C#
SQL = @"BULK INSERT CatTbl FROM 'd:\TEST\TEST.txt' WITH (CODEPAGE=1255,FIELDTERMINATOR = '\t')";
Cmd = new SqlCommand(SQL, Conn);
Cmd.ExecuteNonQuery();
Cmd.Dispose();
Posted
Updated 21-Aug-18 2:17am
v2
Comments
Mehdi Gholam 21-Aug-18 8:31am    
Your .txt file is not accessible from the cloud server, try uploading it to somewhere that server can see and access first.
goldsoft 21-Aug-18 8:56am    
thanks, how to do it ? or how to copy the file to server ?
Herman<T>.Instance 21-Aug-18 9:54am    
C#-> FtpRequest (search on MSDN)
Dave Kreskowiak 21-Aug-18 12:13pm    
That depends entirely on your cloud service and/or your SQL server if it's hosted on a VM. Since nobody knows what that is, nobody can tell you anything about how to do it.

Consult the documentation for your cloud service and your SQL setup.
Eric Lynch 21-Aug-18 12:57pm    
Since you're starting from C#, you may want to check out the following:

https://docs.microsoft.com/en-us/dotnet/framework/data/adonet/sql/bulk-copy-operations-in-sql-server

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900