Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feedback on XML Output Issue #113

Open
Niritl-Madeira opened this issue Nov 17, 2024 · 0 comments
Open

Feedback on XML Output Issue #113

Niritl-Madeira opened this issue Nov 17, 2024 · 0 comments

Comments

@Niritl-Madeira
Copy link

Hi Daniel,

I’ve been using your code, and I must say it’s fantastic! It has saved me a ton of work. Thank you for sharing it!

However, I encountered a small issue while extracting a large table using the XML option and calling your procedure via PowerShell. Here's the code I’ve been using:

$connectionString = "Server=$serverName;Database=$databaseName;Integrated Security=True;"
$connection = New-Object System.Data.SqlClient.SqlConnection($connectionString)
$connection.Open()

# Create a SQL command
$command = $connection.CreateCommand()
$command.CommandText = "EXEC sp_generate_merge @results_to_text = 0, @include_use_db = 0, @max_rows_per_batch = 100, @delete_if_not_matched = 0, @schema = N'dbo', @table_name = N'XXX';"

# Execute the command and read the XML output
$xmlReader = $command.ExecuteXmlReader()

# Load the XML into an XML document
$xmlDocument = New-Object System.Xml.XmlDocument
$xmlDocument.Load($xmlReader)

# Save the XML to a file
$xmlDocument.Save($outputFilePath)

The issue I ran into is that the only way I was able to get the output saved to a file was by changing this line:

SELECT [processing-instruction(x)]=@output FOR XML PATH(''), TYPE;

to:

SELECT @output AS a FOR XML PATH('');

I’m not entirely sure why this change was necessary, but I thought it might be worth bringing to your attention in case there’s something in the XML handling that could be causing it.

Thanks again for your excellent work on this code—it’s been incredibly helpful!

Best regards,
Nirit

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant