MS SQL Server - Bulk Insert Across a Network

前端 未结 5 622
北荒
北荒 2021-01-13 22:32

I have an application that uses MS SQL Server for which I\'ll need to do a bulk insert from a file. The sticking point is that the database and my application will be hoste

5条回答
  •  猫巷女王i
    2021-01-13 23:07

    I'm still looking for a way to do this in MS SQL, but what I did in MySQL was to save the CSV as a BLOB in a temporary table, run SELECT ... INTO DUMPFILE in a directory local to the DB server, then run the regular LOAD DATA statement on that local file (EDIT: I feel I should point out, this was before LOAD DATA LOCAL was available).

    I think spWriteStringToFile will do it.

    EDIT: I'm on to something.

    comm.CommandText = @"EXEC spWriteStringToFile @data, 'c:\datadumps', 'data.csv';
        BULK INSERT my_table FROM 'c:\datadumps\data.csv';";
    comm.Parameters.AddWithValue("data", File.ReadAllText(path));
    comm.ExecuteNonQuery();
    

提交回复
热议问题