当我尝试
BULK INSERT table FROM 'c:\file.txt'
我明白了
Msg 4861, Level 16, State 1, Line 1
Cannot bulk load because the file "c:\file.txt" could not be opened. Operating system error code 32(The process cannot access the file because it is being used by another process.).
错误,因为该文件是另一个进程打开的日志文件。
但是,使用 C#,我可以使用以下方式打开文件System.IO.FileShare.ReadWrite
:
using (System.IO.FileStream fileStream = new System.IO.FileStream("c:\\file.txt", System.IO.FileMode.Open, System.IO.FileAccess.Read, System.IO.FileShare.ReadWrite))
{
using (System.IO.StreamReader streamReader = new System.IO.StreamReader(fileStream))
{
file = streamReader.ReadToEnd();
}
}
有没有办法让 SQL Server 中的读写共享功能(批量插入或任何其他)?
谢谢