{"id":17888103,"url":"https://github.com/fireflycons/invoke-sqlexecute","last_synced_at":"2025-10-27T08:08:48.895Z","repository":{"id":96974369,"uuid":"144995214","full_name":"fireflycons/Invoke-SqlExecute","owner":"fireflycons","description":"A complete replacement for Invoke-Sqlcmd with bugs in the former addressed","archived":false,"fork":false,"pushed_at":"2021-08-03T04:30:09.000Z","size":43180,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-04-03T02:42:24.104Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"C#","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/fireflycons.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2018-08-16T13:57:51.000Z","updated_at":"2019-08-14T06:12:33.000Z","dependencies_parsed_at":null,"dependency_job_id":"78bcaa23-4f13-4057-b4ba-37f7fe192fbb","html_url":"https://github.com/fireflycons/Invoke-SqlExecute","commit_stats":null,"previous_names":[],"tags_count":3,"template":false,"template_full_name":null,"purl":"pkg:github/fireflycons/Invoke-SqlExecute","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fireflycons%2FInvoke-SqlExecute","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fireflycons%2FInvoke-SqlExecute/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fireflycons%2FInvoke-SqlExecute/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fireflycons%2FInvoke-SqlExecute/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/fireflycons","download_url":"https://codeload.github.com/fireflycons/Invoke-SqlExecute/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fireflycons%2FInvoke-SqlExecute/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":281235246,"owners_count":26466162,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-10-27T02:00:05.855Z","response_time":61,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-10-28T13:36:34.071Z","updated_at":"2025-10-27T08:08:48.865Z","avatar_url":"https://github.com/fireflycons.png","language":"C#","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Invoke-SqlExecute\n\n|Branch|Status|\n|------|------|\n|master|[![Build status](https://ci.appveyor.com/api/projects/status/1p6dvf2gldjj1t1h/branch/master?svg=true)](https://ci.appveyor.com/project/fireflycons/invoke-sqlexecute/branch/master)|\n|dev|[![Build status](https://ci.appveyor.com/api/projects/status/1p6dvf2gldjj1t1h/branch/dev?svg=true)](https://ci.appveyor.com/project/fireflycons/invoke-sqlexecute/branch/dev)|\n\n*Work In Progress - there may well be bugs!*\n\nYou are strongly advised to test thoroughly within a non-production environment before letting this loose on any production system!\n\nTL;DR - Jump to [Invoke-SqlExecute command syntax](./docs/en-US/Invoke-SqlExecute.md)\n\n# Installation\n\nThe module is published on the PowerShell Gallery and can be installed by following the instructions there\n\nhttps://www.powershellgallery.com/packages/Firefly.InvokeSqlExecute\n\n# About\n\nA complete replacement for the Invoke-Sqlcmd cmdlet with bugs in the former addressed. The code has no external dependencies and should work with whatever SMO version it finds when running within the PowerShell SQL provider context.\n\nAnother big bugbear of mine is the tersity of error messages returned by the standard implementations. SQL server only knows about the currently executing batch and thus the error details will refer to the line number within the batch. If you have a huge SQL file with hundreds or thousands of batches in, it is more useful to know which line within the *entire* input file is the one with the error. The parser in this implementation tracks the line number of the start of each batch within the input and adds this to the line number reported by SQL server to give you the true location of the erroneous statement as near as possible, and that includes descent into files refrenced with `:r` - for instance:\n\n```\nSqlException caught!\nClient:              APPVYR-WIN\nServer:              (local)\\SQL2017\nBatch:               C:\\Users\\appveyor\\AppData\\Local\\Temp\\1\\sql-server-samples\\samples\\databases\\adventure-works\\data-warehouse-install-script\\instawdbdw.sql, beginning at line 738\nMessage:             Cannot bulk load because the file \"C:\\Users\\appveyor\\AppData\\Local\\Temp\\1\\sql-server-samples\\samples\\databases\\adventure-works\\data-warehouse-install-script\\DimAccount.csv\" could not be opened. Operating system error code 5(Access is denied.).\nSource:              .Net SqlClient Data Provider\nNumber:              4861\nClass:               16\nState:               1\nLine (within batch): 12\nLine (within file):  749\nError near:\nBULK INSERT [dbo].[DimAccount] FROM 'C:\\Users\\appveyor\\AppData\\Local\\Temp\\1\\sql-server-samples\\samples\\databases\\adventure-works\\data-warehouse-install-script\\DimAccount.csv'\nWITH (\n    CHECK_CONSTRAINTS,\n   -- CODEPAGE='ACP',\n    DATAFILETYPE = 'widechar',\n    FIELDTERMINATOR= '|',\n    ROWTERMINATOR = '\\n',\n    KEEPIDENTITY,\n    TABLOCK\n);\n```\n\n## Enhancements\n\n### SQLCMD command support\n\nThis implementation also includes support for more non-interactive 'colon commands' than are available in Invoke-sqlcmd such as `:CONNECT`, `:OUT`, `:!!` etc.\n\n### Parallel Execution\n\nUsing the `-Parallel` switch, the following scenarios will run simultaneously. If the switch is omitted the scripts will run sequentially in the order they were presented to the command.\n\n* Run a single script on multiple connections, e.g. deploy database to several servers\n* Run multiple scripts on a single connection\n* Run multiple scripts each with their own connection.\n\n### :SETVAR Enhancement\n\nUsing the `-OverrideScriptVariables` switch will prevent any `:SETVAR` within scripts from resetting the value of a scripting variable set from the command line.\n\n### Capture console output with a PowerShell ScriptBlock\n\nWhilst you can use `-OutFile` or even pipe console output to `Tee-Object`, using `-ConsoleMessageHandler` with a PowerShell script block gives you far more control over how you handle the output, as context is provided along with the message text - which node it came from (when `-Parallel`) and whether it is destined for the output or error stream. Use this mechanism to feed information to custom loggers e.g. build engines, or simply to change the formatting of the message.\n\n### Batch Retry\n\nWith `-RetryCount` you can specify a number of times to retry a failed batch. Retrys are possible for timeout or deadlock victim errors. \n\nBe aware that the entire batch is resubmitted if you use this feature.\n\n## Supported Environments\n\nCI builds are run against the following SQL server versions. This is not to say that other versions won't work, however they aren't present in the AppVeyor CI system.\n\n* Microsoft SQL Server 2014 - 12.0.4100.1\n* Microsoft SQL Server 2016 (SP1-CU8) (KB4077064) - 13.0.4474.0\n* Microsoft SQL Server 2017 (RTM) - 14.0.1000.169\n* Microsoft LocalDB 2016 (SP1-CU8) (KB4077064) - 13.0.4474.0\n\n## Specific Bugs Addressed\n\n* [Invoke-Sqlcmd and error results](https://sqldevelopmentwizard.blogspot.com/2016/12/invoke-sqlcmd-and-error-results.html)\n* [Invoke-Sqlcmd runs script twice](https://stackoverflow.com/questions/33271446/invoke-sqlcmd-runs-script-twice/)\n* `-IncludeSqlUserErrors` switch (I think this is a bug): In the MS implementation, this parameter forces a datareader with no returned rows to iterate all available result sets in the batch. This is the only way an error raised on any statement within the batch other than the first one will raise a `SqlException`. This parameter is provided for command line compatibility with Invoke-Sqlcmd, but the execution engine behaves as though it is always set.\n\nIf you are aware of any other bugs or inconsistencies in Invoke-Sqlcmd where the behaviour does not align with that of SSMS or sqlcmd.exe, please contact me and I will correct it in this implementation or you can fork it and submit a PR.\n\n\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffireflycons%2Finvoke-sqlexecute","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ffireflycons%2Finvoke-sqlexecute","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffireflycons%2Finvoke-sqlexecute/lists"}