ConstantineK / sqlshell

Lightweight TSQL PowerShell Module
GNU General Public License v2.0
3 stars 1 forks source link

Is there a benefit for an internal and external connection command? #2

Open ConstantineK opened 6 years ago

ConstantineK commented 6 years ago

One thing we see in dbatools is a lot of work with a lot of tuning is maintain two connection commands to surface different options.

I want to understand more about why this happens and what benefits or downsides I can find, and see if I can isolate the effort inside of one command, or clearly document the bright lines between them.

ConstantineK commented 6 years ago

Checking out Connect-SqlInstance, looks like there's a few items in here that are to manage old version compatibility (with fairly good comments) but I am going to remove them for now.

ConstantineK commented 6 years ago

This code implies to me we need a standardized function that takes in whatever identifier a human would use for an instance, and comes out with a useful SMO Server object (even within the connection functions.)

Once we can do that construction, I think the next question to ask is how much the super tuning on connection timing helps, so I am going to write some tests around connection enumeration and see if I can show the cost/benefit.

ConstantineK commented 6 years ago

I think the other open question that this implies is - do we really want to have SqlCredential for every command? I am not too worried about it, but when I think about it more deeply I dont know if its the right choice.

It allows cool passthrough in many cases, but it actually kind of goes into what we are trying to do with the module, and really "How does a sql connection work." (something ephemeral or explicit.)

Do we:

I am just trying to think what sending in the credential gets you separately - and really you might able to build the connection from scratch again after you dispose of the object, but I almost feel like that's an anti-feature?

SirCaptainMitch commented 6 years ago

I think there is value to having a credential param on each command, having used it pretty heavily in all of my commands it makes life a lot easier to not have to build the object manually each time and instead build the credential object with a secret. So I think we need to consider the SQL Login folks out there, because they do exist and I am one of them (for now).

The first option is pretty heavy in that respect.

Ideally, if a function is called and it's just given a name, I would expect the function to attempt to build that object on it's own calling the main Create-SMOObject function. I can see a need for abstraction and keeping the function to its own devices and being expect to pass in a proper object, I just think it adds a lot for the end user to do.