久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

    <legend id='4PYoS'><style id='4PYoS'><dir id='4PYoS'><q id='4PYoS'></q></dir></style></legend>
      <bdo id='4PYoS'></bdo><ul id='4PYoS'></ul>
  1. <tfoot id='4PYoS'></tfoot>

    1. <small id='4PYoS'></small><noframes id='4PYoS'>

      <i id='4PYoS'><tr id='4PYoS'><dt id='4PYoS'><q id='4PYoS'><span id='4PYoS'><b id='4PYoS'><form id='4PYoS'><ins id='4PYoS'></ins><ul id='4PYoS'></ul><sub id='4PYoS'></sub></form><legend id='4PYoS'></legend><bdo id='4PYoS'><pre id='4PYoS'><center id='4PYoS'></center></pre></bdo></b><th id='4PYoS'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='4PYoS'><tfoot id='4PYoS'></tfoot><dl id='4PYoS'><fieldset id='4PYoS'></fieldset></dl></div>

      為什么我需要手動打開這個 .NET Core 數(shù)據(jù)庫連接,

      Why do I need to manually open this .NET Core database connection when usually Dapper auto opens it?(為什么我需要手動打開這個 .NET Core 數(shù)據(jù)庫連接,而通常 Dapper 會自動打開它?) - IT屋-程序員軟件開發(fā)技術(shù)分享
    2. <i id='JZxz2'><tr id='JZxz2'><dt id='JZxz2'><q id='JZxz2'><span id='JZxz2'><b id='JZxz2'><form id='JZxz2'><ins id='JZxz2'></ins><ul id='JZxz2'></ul><sub id='JZxz2'></sub></form><legend id='JZxz2'></legend><bdo id='JZxz2'><pre id='JZxz2'><center id='JZxz2'></center></pre></bdo></b><th id='JZxz2'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='JZxz2'><tfoot id='JZxz2'></tfoot><dl id='JZxz2'><fieldset id='JZxz2'></fieldset></dl></div>
          <tbody id='JZxz2'></tbody>
          <legend id='JZxz2'><style id='JZxz2'><dir id='JZxz2'><q id='JZxz2'></q></dir></style></legend>
            <bdo id='JZxz2'></bdo><ul id='JZxz2'></ul>
            <tfoot id='JZxz2'></tfoot>

            <small id='JZxz2'></small><noframes id='JZxz2'>

                本文介紹了為什么我需要手動打開這個 .NET Core 數(shù)據(jù)庫連接,而通常 Dapper 會自動打開它?的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)吧!

                問題描述

                限時送ChatGPT賬號..

                我正在嘗試使用 async/await 將一些記錄插入到數(shù)據(jù)庫中.如果我不手動打開連接,我會收到 Exception.如果我添加一些代碼來打開連接,那么一切正常.

                這是當(dāng)前代碼(拋出異常):

                using (var connection = new SqlConnection(ConnectionString)){var tasks = new List();sellUrls.ForEach(url => tasks.Add(InsertUrlAsync(connection, url)));rentUrls.ForEach(url => tasks.Add(InsertUrlAsync(connection, url)));等待 Task.WhenAll(tasks);}...私有異步任務(wù) InsertUrlAsync(IDbConnection 連接,字符串 url){const string query = "INSERT INTO ..";return await connection.ExecuteAsync(query, new { .. });}

                異常:

                <塊引用>

                消息:System.InvalidOperationException:操作無效.連接已關(guān)閉.

                但是當(dāng)我將代碼更改為以下內(nèi)容時,它起作用了:

                var tasks = new List();等待 connection.OpenAsync();sellUrls.ForEach(....) .. 等等...

                類似的問題:

                • Task.WhenAll,連接正在關(guān)閉
                • SqlConnection 在 using 語句中意外關(guān)閉

                解決方案

                Dapper 為您打開連接;但它也會在工作完成后關(guān)閉它.

                現(xiàn)在,您正在使用一個連接運行兩個獨立的 async 任務(wù).

                <塊引用>

                soldUrls.ForEach(url => tasks.Add(InsertUrlAsync(connection, url)));rentUrls.ForEach(url => tasks.Add(InsertUrlAsync(connection, url)));

                兩個任務(wù)同時運行.當(dāng)一項任務(wù)的工作完成時,它關(guān)閉連接.但是其他任務(wù)仍在運行,它不再有權(quán)訪問打開的連接,因此出現(xiàn)了您提到的異常.

                如您所說,如果您自己打開連接,Dapper 不會關(guān)閉它,一切正常.

                順便說一下,在并發(fā)使用連接實例時,可能會出現(xiàn)意想不到的問題.請參閱此問題了解更多詳情.

                I'm trying to use async/await to insert a number of records into a database. If I don't manually open the connection, I get an Exception. If I add some code to open the connection, then everything works ok.

                Here's the current code (which throws an Exception):

                using (var connection = new SqlConnection(ConnectionString))
                {
                    var tasks = new List<Task>();
                    soldUrls.ForEach(url => tasks.Add(InsertUrlAsync(connection, url))); 
                    rentUrls.ForEach(url => tasks.Add(InsertUrlAsync(connection, url)));
                    await Task.WhenAll(tasks);
                }
                
                ...
                
                private async Task InsertUrlAsync(IDbConnection connection, string url)
                {
                    const string query = "INSERT INTO ..";
                    return await connection.ExecuteAsync(query, new { .. });
                }
                

                the exception:

                Message: System.InvalidOperationException : Invalid operation. The connection is closed.

                but when I change the code to the following, it works:

                var tasks = new List<Task>();
                await connection.OpenAsync();
                soldUrls.ForEach(....) .. etc ... 
                
                

                Similar SO questions:

                • Task.WhenAll, connection is closing
                • SqlConnection closes unexpectedly inside using statement

                解決方案

                Dapper opens the connection for you; but it also closes it when work is done.

                Now, you are running two independent async tasks using one single connection.

                soldUrls.ForEach(url => tasks.Add(InsertUrlAsync(connection, url))); 
                rentUrls.ForEach(url => tasks.Add(InsertUrlAsync(connection, url)));
                

                Both the tasks are running simultaneously. When work of one task finish, it closes the connection. But other task is still running which does not have access to open connection anymore and hence the exception you mentioned in question.

                As you said, if you open the connection yourself, Dapper does not close it and everything just works fine.

                By the way, while using connection instance concurrently, there may be unexpected issues. Please refer to this question for more details.

                這篇關(guān)于為什么我需要手動打開這個 .NET Core 數(shù)據(jù)庫連接,而通常 Dapper 會自動打開它?的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網(wǎng)!

                【網(wǎng)站聲明】本站部分內(nèi)容來源于互聯(lián)網(wǎng),旨在幫助大家更快的解決問題,如果有圖片或者內(nèi)容侵犯了您的權(quán)益,請聯(lián)系我們刪除處理,感謝您的支持!

                相關(guān)文檔推薦

                Can I figure out a list of databases and the space used by SQL Server instances without writing SQL queries?(我可以在不編寫 SQL 查詢的情況下找出數(shù)據(jù)庫列表和 SQL Server 實例使用的空間嗎?) - IT屋-程序員軟件開發(fā)
                How to create a login to a SQL Server instance?(如何創(chuàng)建對 SQL Server 實例的登錄?)
                How to know the version and edition of SQL Server through registry search(如何通過注冊表搜索知道SQL Server的版本和版本)
                Why do I get a quot;data type conversion errorquot; with ExecuteNonQuery()?(為什么會出現(xiàn)“數(shù)據(jù)類型轉(zhuǎn)換錯誤?使用 ExecuteNonQuery()?)
                How to show an image from a DataGridView to a PictureBox?(如何將 DataGridView 中的圖像顯示到 PictureBox?)
                WinForms application design - moving documents from SQL Server to file storage(WinForms 應(yīng)用程序設(shè)計——將文檔從 SQL Server 移動到文件存儲)
                  <bdo id='lwwTb'></bdo><ul id='lwwTb'></ul>
                      <tbody id='lwwTb'></tbody>
                    • <i id='lwwTb'><tr id='lwwTb'><dt id='lwwTb'><q id='lwwTb'><span id='lwwTb'><b id='lwwTb'><form id='lwwTb'><ins id='lwwTb'></ins><ul id='lwwTb'></ul><sub id='lwwTb'></sub></form><legend id='lwwTb'></legend><bdo id='lwwTb'><pre id='lwwTb'><center id='lwwTb'></center></pre></bdo></b><th id='lwwTb'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='lwwTb'><tfoot id='lwwTb'></tfoot><dl id='lwwTb'><fieldset id='lwwTb'></fieldset></dl></div>

                        <small id='lwwTb'></small><noframes id='lwwTb'>

                          <tfoot id='lwwTb'></tfoot>

                        1. <legend id='lwwTb'><style id='lwwTb'><dir id='lwwTb'><q id='lwwTb'></q></dir></style></legend>
                          主站蜘蛛池模板: 97视频人人澡人人爽 | 精品少妇一区二区三区在线播放 | 久久久久国产一区二区三区四区 | 国产精品黄视频 | 五月天国产视频 | 日屁视频 | 欧美精品一二区 | 国产色婷婷精品综合在线播放 | 日日操夜夜操天天操 | 最新超碰 | 久久久久久黄 | 欧美一级免费片 | 性做久久久久久免费观看欧美 | 91小视频| 精品日韩一区 | 久久精品久久久久久 | 亚洲视频精品在线 | 欧美一级欧美三级在线观看 | 日本亚洲精品成人欧美一区 | 在线免费观看黄色av | 日韩在线精品 | 国产yw851.c免费观看网站 | 欧美视频 亚洲视频 | 久草免费在线视频 | 日韩欧美国产一区二区 | 精品免费国产一区二区三区四区介绍 | 国产一区二区激情视频 | 日日操夜夜操天天操 | 日韩区 | 精品视频一区二区 | www.黄色网 | 日本激情视频中文字幕 | 国产.com | 一区二区高清 | 99精品在线 | 国产高清精品网站 | 免费视频成人国产精品网站 | 亚洲午夜精品 | 黄色欧美大片 | 亚洲精品日韩在线 | 亚洲日日操 |