Comments (5)
I like the idea of combing into a single resource. I do have two comments after reading this
- Is there a reason we'd drop the use of the
DisableVariable
parameter? I currently rely on the ability to disable them to be able to add some of the solutions provided by the SQL Server Maintenance Solution viaSqlScript
resources. I promise it's not just me being biased since I added the support for it. 😆 - If work is going to be done on the this resource, and while this is fresh in my mind from the last PR #1916, should we consider adding in the
ConnectTimeout
property here and toConnect-SQL
function instead of reusing theStatementTimeout
? It might not be necessary, but it is probably better to control the two independently. Waiting to connect to an offline server for 10 minutes instead of 30 seconds might not be the end of the world but at least that can be up the author of their config.
from sqlserverdsc.
Is there a reason we'd drop the use of the DisableVariable parameter?
My thought that the parameter were not needed if we move away from using Invoke-SqlCmd
and instead using ExecuteNonQuery() and ExecuteWithResults methods on the SMO database object. Not even sure if we need the parameter Variable
as we could use PowerShell to build the query strings, my thought was to leave out the Variable
parameter in a first iteration until there is a god use case for it.
should we consider adding in the ConnectTimeout property here and to Connect-SQL function instead of reusing the StatementTimeout?
I agree that it is probably better to control the two independently. We should also move the logic in Connect-Sql
to the public function Connect-SqlDscDatabaseEngine
so we could make it better then at the same time. 🤔
from sqlserverdsc.
My thought that the parameter were not needed if we move away from using Invoke-SqlCmd and instead using ExecuteNonQuery() and ExecuteWithResults methods
Okay, this should be straight forward just execute the string.
Not even sure if we need the parameter
Variable
as we could use PowerShell to build the query strings
Not quite sure I follow what this would look like with the proposed resource. I use the variable feature as often as possible to simplify and reuse scripts across multiple resources. Here is a simple example
Existing DSC Resource Example
SqlScript 'UpdateSchedule1'
{
ServerName = $serverName
InstanceName = $sqlInstanceName
GetFilePath = "$PSScriptRoot\updateJobStartTime\getScript.sql"
SetFilePath = "$PSScriptRoot\updateJobStartTime\setScript.sql"
TestFilePath = "$PSScriptRoot\updateJobStartTime\testScript.sql"
Variable = "jobName='My Job Step 1'",
("activeStartTime={0}" -f $localStartTime1)
PsDscRunAsCredential = $credential
}
SqlScript 'UpdateSchedule2'
{
ServerName = $serverName
InstanceName = $sqlInstanceName
GetFilePath = "$PSScriptRoot\updateJobStartTime\getScript.sql"
SetFilePath = "$PSScriptRoot\updateJobStartTime\setScript.sql"
TestFilePath = "$PSScriptRoot\updateJobStartTime\testScript.sql"
Variable = "jobName='My Job Step 2'",
("activeStartTime={0}" -f $localStartTime2)
PsDscRunAsCredential = $credential
}
T-SQL getScript.sql from above file
EXEC dbo.sp_update_schedule
@name = $(jobName),
@active_start_time = $(activestartTime)
GO
I realize there are a few ways to handle substitution or string building in PowerShell natively, but in the context of the proposed resource I'm not sure what that looks like. Is the expectation that you'd just handle that outside the resource completely?
I agree that it is probably better to control the two independently. We should also move the logic in
Connect-Sql
to the public functionConnect-SqlDscDatabaseEngine
so we could make it better then at the same time. 🤔
I wasn't sure if it would be best to lump it in with this proposal, but it is related and might be as good a time as any other to improve both.
from sqlserverdsc.
I realize there are a few ways to handle substitution or string building in PowerShell natively, but in the context of the proposed resource I'm not sure what that looks like. Is the expectation that you'd just handle that outside the resource completely?
Ah, for files then the Variable would be a necessity, then we can't parse the strings in the configuration that we can do for the string that is passed to the suggested parameter GetQuery
.
I guess we then need parameter Variable
. If parameter variable is assigned a value then we can run logic that parses the query that is passed in the parameter GetQuery
or parse the content of the files that is passed in the parameter GetQueryFilePath
. I'm thinking that Variable
is a hashtable (or mor exactly an instance of MSFT_KeyValuePair
) instead of an string array for better handling, similar to xRemoteFile.
So in the example would instead look like this:
SqlQuery 'UpdateSchedule2'
{
ServerName = $serverName
InstanceName = $sqlInstanceName
GetQueryFilePath = "$PSScriptRoot\updateJobStartTime\getScript.sql"
SetQueryFilePath = "$PSScriptRoot\updateJobStartTime\setScript.sql"
TestQueryFilePath = "$PSScriptRoot\updateJobStartTime\testScript.sql"
Variable = @{
jobName = 'My Job Step 2'
activeStartTime = '{0}' -f $localStartTime2
}
PsDscRunAsCredential = $credential
}
Then, since the parameter Variable
was passed I'm thinking it would parse the content the file, e.g in the example it would loop through the variables (the keys) in the hashtable and look for $(jobName)
and replace it.
EXEC dbo.sp_update_schedule
@name = $(jobName),
@active_start_time = $(activestartTime)
GO
to
EXEC dbo.sp_update_schedule
@name = 'My Job Step 2',
@active_start_time = '2023-04-26 09:00:00'
GO
Would that work?
from sqlserverdsc.
Would it be a problem parsing some of the variables depending on the data type or can all be made strings so they are converted automatically by SQL Server? 🤔 I feel it was a long time since I manipulated data types in T-SQL 🙂
from sqlserverdsc.
Related Issues (20)
- SqlServerDsc: Release assets on a GitHub release HOT 2
- SqlScriptQuery: Get-Module for SQLPS throws error HOT 6
- SqlConfiguration - 'blocked process threshold' option support HOT 3
- SqlServerDsc: Using AMO client library for `Microsoft.AnalysisServices.Server` HOT 1
- Error while running the DSC_SqlSetup Module HOT 1
- SqlProtocolTcpIp: Auto-detect the TCP/IP address group name by IP address HOT 6
- SqlSecureConnection: Unable to specify certificate by using friendly name HOT 5
- SqlWindowsFirewall: Duplicate Browser Firewall Rule for AS feature creates Error in subsequent Test-TargetResource runs HOT 3
- SqlServerDsc: GitHub Action Code Analysis should run on built module HOT 1
- SqlSetup: Seems to evaluate the `SourcePath` too early for Puppet HOT 6
- Problem using dsc_sqlscript as a resource in puppet HOT 3
- SqlDatabasePermission: Problem using dsc_sqldatabasepermission in Puppet HOT 4
- SqlLogin: Attempting to disable and already disabled login throws an error
- SqlPermission: Undefined DSC resource 'SqlPermission' HOT 8
- Table of Contents broken HOT 3
- Install-SqlDscServer with -PrepareImage errors when InstanceName is specified HOT 1
- `Get-SqlDscPreferredModule`: Should be possible to specify which version of the SqlServer module is imported HOT 9
- SqlServerDsc: Implement release assets (GitHub releases) HOT 1
- SqlServerDsc: Look at using CODEOWNERS file HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from sqlserverdsc.