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

使用 Powershell 從 SQL 輸出大型 XML 文件

Outputting large XML file from SQL with Powershell(使用 Powershell 從 SQL 輸出大型 XML 文件)
本文介紹了使用 Powershell 從 SQL 輸出大型 XML 文件的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

問題描述

限時送ChatGPT賬號..

我有一個 Powershell 腳本,它調(diào)用 SQL 服務器中的存儲過程并將結(jié)果 XML 直接輸出到文件.它適用于較小的測試文件,但會下降到完整大小(~1.5gb 文件).

I have a Powershell script that calls a stored procedure in SQL server and outputs the resulting XML directly to a file. It works for a smaller test file but falls down with the full size (~1.5gb file).

存儲過程工作正常.我可以在 SQL 服務器中調(diào)用它 - 問題是我必須在 SQL 服務器中打開它,然后手動將它保存到一個文件,然后編輯該文件以刪除換行符.當我運行腳本時,它會在最后嘗試刪除中間文件時崩潰.但是,當我一行一行地運行它時,它會落在 invoke-sql 行.

The stored procedure works fine. I can call it within SQL server - the problem is that I have to open it in the SQL server then manually save it to a file, then edit that file to remove newlines. When I run the script it falls down when it tries to delete the intermediary files at the end. However, when I run it line by line it falls down at the invoke-sql line.

#net use S: "\\processStore\projects"

# Create variables
$SQLquery = "DECLARE @return_value int; EXEC @return_value = [XML].[XMLdata];"
$outpath = "D:\MyDocuments\XML\XML files" 
$outfile = "TestOutput"

# Run the SQL command and store the object to a variable. Need to extend the timeout from the default.
$sql = invoke-sqlcmd -Database 'APP2021' -Query $SQLquery -serverinstance 'statdata' -QueryTimeout 100000

cd C:

# Store the SQL output as an interim text file
$sql.{XML_F52E2B61-18A1-11d1-B105-00805F49916B} | out-file -Filepath "$outpath\$outfile.txt" 

# Remove Linebreaks
(Get-Content "$outpath\$outfile.txt" -Raw).Replace("`r`n","") | Set-Content "$outpath\${outfile}_del.xml" -Force
format-xml "$outpath\${outfile}_del.xml" | Set-Content "$outpath\$outfile.xml" -Force

# Delete interim text files
del "$outpath\$outfile.txt"
del "$outpath\${outfile}_del.xml"

當一行一行地運行時,代碼在 invoke-sqlcmd 行出現(xiàn)錯誤:

When running lines one by one the code falls down at the invoke-sqlcmd line with the error:

invoke-sqlcmd : A transport-level error has occurred when receiving results from the server. (provider: TCP Provider, error: 0 - An existing connection was forcibly closed by the remote 
host.)
At line:1 char:8
+ $sql = invoke-sqlcmd -Database 'APP2021' -Query $SQLquery -serverinst ...
+        ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidOperation: (:) [Invoke-Sqlcmd], SqlPowerShellSqlExecutionException
    + FullyQualifiedErrorId : SqlError,Microsoft.SqlServer.Management.PowerShell.GetScriptCommand

推薦答案

Change from
invoke-sqlcmd -Database 'APP2021' -Query $SQLquery -serverinstance 'statdata' -QueryTimeout 100000

invoke-sqlcmd -Database 'APP2021' -Query $SQLquery -serverinstance 'statdata' -QueryTimeout 0

Change from
invoke-sqlcmd -Database 'APP2021' -Query $SQLquery -serverinstance 'statdata' -QueryTimeout 100000
to
invoke-sqlcmd -Database 'APP2021' -Query $SQLquery -serverinstance 'statdata' -QueryTimeout 0

設置 QueryTimeout = 0 將防止查詢超時

這篇關(guān)于使用 Powershell 從 SQL 輸出大型 XML 文件的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網(wǎng)!

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

相關(guān)文檔推薦

What SQL Server Datatype Should I Use To Store A Byte[](我應該使用什么 SQL Server 數(shù)據(jù)類型來存儲字節(jié) [])
Interpreting type codes in sys.objects in SQL Server(解釋 SQL Server 中 sys.objects 中的類型代碼)
Typeorm .loadRelationCountAndMap returns zeros(Typeorm .loadRelationCountAndMap 返回零)
MS SQL: Should ISDATE() Return quot;1quot; when Cannot Cast as Date?(MS SQL:ISDATE() 是否應該返回“1?什么時候不能投射為日期?)
Converting the name of a day to its integer representation(將一天的名稱轉(zhuǎn)換為其整數(shù)表示)
How to convert nvarchar m/d/yy to mm/dd/yyyy in SQL Server?(如何在 SQL Server 中將 nvarchar m/d/yy 轉(zhuǎn)換為 mm/dd/yyyy?)
主站蜘蛛池模板: 一级毛片成人免费看a | 翔田千里一区二区 | 免费看a | 国产98色在线 | 5060网一级毛片 | 亚洲国产精品网站 | 久久久久久高清 | 欧美片网站免费 | 国产一区二区三区四区 | 亚洲一区二区在线 | 国产精品亚洲欧美日韩一区在线 | 欧美精品啪啪 | 午夜精品一区 | 四虎永久免费影院 | 福利一区在线观看 | 免费观看a级毛片在线播放 黄网站免费入口 | 欧美视频成人 | 91中文在线观看 | 欧美爱爱视频 | jav成人av免费播放 | 欧美一区二区三区在线播放 | 欧美午夜一区 | 黄色片视频 | 亚洲精品免费在线 | 请别相信他免费喜剧电影在线观看 | 国产综合第一页 | 日韩资源 | 四虎在线观看 | 久草新在线 | 一区二区三区回区在观看免费视频 | 日韩av在线免费 | 成人免费在线视频 | 综合色站导航 | 欧美视频一区二区三区 | 亚洲网站观看 | av午夜电影 | 香蕉久久久 | 日本中文字幕在线视频 | 久久免费精品 | 人人玩人人添人人澡欧美 | 久久精品高清视频 |