批量插入3M记录到SQLExpress

发布于 2024-09-25 00:22:27 字数 584 浏览 0 评论 0原文

当尝试将 3M 记录从 CSV 文件批量插入到 SQLExpress 数据库时,该过程抛出超时异常,该异常设置为 30 秒。我尝试将连接超时设置为 1800,但该过程再次引发了相同的异常。

有谁知道抛出异常是由于记录太多还是超时设置不正确?

下面是连接字符串、查询语句和文件中的行,

connectionString = "Data Source=.\SQLEXPRESS;AttachDbFilename=simulatorDB.mdf;Integrated Security=True;Connect Timeout=1800;User Instance=True"

query = "BULK INSERT real_data FROM '" + path + "' WITH (FIELDTERMINATOR = ',', ROWTERMINATOR = '\n')"

AFAB19476C2CEEEE101FFA45FD207BA8B6185B29,539EE0643AFC3A3BE3D20DC6BE7D5376DC536D34,9800,58,29,24,34,2

如果有人建议修复所描述的问题,我将非常感激。

谢谢你!

While trying to bulk insert 3M records from CSV file to SQLExpress database the procedure throw the timeout exception which was set to 30s. I tried to set the Connect Timeout to 1800 but again the procedure threw the same exception.

Does anyone know whether the exception is thrown due to too many records or the timeout was not set correctly?

Below is the connection string, query statement and row from file

connectionString = "Data Source=.\SQLEXPRESS;AttachDbFilename=simulatorDB.mdf;Integrated Security=True;Connect Timeout=1800;User Instance=True"

query = "BULK INSERT real_data FROM '" + path + "' WITH (FIELDTERMINATOR = ',', ROWTERMINATOR = '\n')"

AFAB19476C2CEEEE101FFA45FD207BA8B6185B29,539EE0643AFC3A3BE3D20DC6BE7D5376DC536D34,9800,58,29,24,34,2

I would be very thankful if anyone suggested a fix for the described issue.

Thank you!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

浅唱々樱花落 2024-10-02 00:22:27

这不是您需要设置的连接超时 - 您需要增加的是 命令超时

至于导入 3M 记录需要多长时间,这完全取决于您要导入的表 - 即,它是新表还是已经存在一些数据/索引的现有表,该表是否正在被其他进程积极使用。

It's not the connection timeout you need to set - what you need to increase is the Command Timeout.

As for how long importing 3M records will take, it depends exactly on the table you are importing into - i.e. if it's a new table or existing table with some data/indexes already on, whether the table is actively being used by other processes.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文