-
Notifications
You must be signed in to change notification settings - Fork 3
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
Bug fixes and a new Force option for Remove-SqlDatabase #9
Conversation
If we fail to connect to the provide SQL Instance (e.g. .\SQLEXPRESS), this method will fail silently with no error information returned to the caller.
This is useful for removing a database that was created in multi-user mode as there may be cached conenctions to SQL still open after running integration tests.
Alter: http://msdn.microsoft.com/en-us/library/ms205115.aspx - PLS! |
Yeah, they should probably all be If for some reason Write-Error '[ERROR]: DB update completed with errors.`n$($_.ToString()) |
You know what though, I think that I didn't And at the end the output is rounded up for display by Adding additional Could you double check this in your tests. Start with an |
And you should also see it inside |
Errors thrown here were not being added to the $Error collection- I tested this. If I do, say, $Error[0].ToString, I get "cannot index into a null array". That's why I did $_.ToString() - not sure what's up with this. |
Hmm... let me run a quick test of something here. Maybe |
Nopers, function Test
{
$Error.Clear()
try
{
throw 'Foo'
}
catch
{
Write-Host 'foo'
}
Write-Host "There are $($Error.Count) local errors"
} |
Could be related to the fact that this is a module? When I execute and disable access for the connecting user (sa), the error is swallowed and never reported. My first thought was to check the $error collection, but I got the error above (cannot index into a null array). |
I did run across a scoping issue before.. where the Powershell guys made a bit of a strange call |
This is why you see, for instance.. https://github.com/derfsplat/Midori/blob/d51f918b4bee33a94bd9f75b04e558dbad803f4f/tools/Sql.psm1#L1002 |
Trying to remember.. but perhaps its the TODO that I have there that needs to be addressed. There must have been some reason that I didn't just turn it into a throw though. That catch block was definitely hit when you added the Write-Host logging in? ... because I'm not sure how a caught exception wouldn't end up in |
Yes it was. I can repro and send you screen shots??? I'm not sure how I can test for the case I ran into bc it involved specifically the SqlException of login failed in that specific section of script. The error was swallowed and the rest of the scripts carried on merrily. |
I just repro'd a fail locally (outside of Psake) with what's in there.
The exception definitely makes it into the $Error collection. |
If I simulate how Psake dumps the output (basically by |
Ok -- I think maybe the best thing here is to rethrow in the catch, rather than logging anything. I don't think there's a problem with the Exception ending up in Which is I think your primary issue here... that the script continues to execute despite having some sort of SQL connectivity problem. You can test this pretty easy function SqlTest
{
Invoke-SqlFileSmo -Path c:\source\midori\tools\foo.sql -UserName sa -Password booboo -Database '.\SQLEXPRESS'
Write-Host 'The script proceeded'
} In the current script, you get I will push up the rethrow tweak -- you can kill those changesets from your pull and I'll pull in the other little tweaks. |
Nvm.. I just cherry picked the 2 changesets in. |
Below is the output from the build script with the "sa" user disabled. Note how the script clearly enters the catch block, does not throw an error, and then continues. The build finishes successfully. Without an explicit output in the catch block, you'd never know there was an error. Along with trying to print the $Error[0] object, I also tried an explicit "throw"- neither resulted in an exception. FYI: Changing the Write-Host to Write-Error will throw the error, but you have to explicitly Write-Error. Generating post script for temporary database [START] - Running E:\Development\Source\Hg\fieldcomm\build\BuildArtifacts\Database\TestData.sql against .\SQLEXPRESS on db FDFGBZgDuK xUnit.net console test runner (64-bit .NET 4.0.30319.17626) xunit.dll: Version 1.9.1.1600 |
No description provided.