@@ -36,54 +36,58 @@ $this.ExecuteNonQuery($Command)
36
36
<Name >Query</Name >
37
37
<Script >
38
38
param (
39
- $Query,
40
- $Database,
41
- $AllTables = $false
39
+ [string] $Query,
40
+ [string] $Database,
41
+ [bool] $AllTables
42
42
)
43
43
44
- if (-not $Database) {
45
- if ($this.ConnectionContext.DatabaseEngineType -eq "SqlAzureDatabase") {
46
- $Database = $this.ConnectionContext.ExecuteScalar("select db_name()")
47
- if (-not $Database) {
48
- $Database = $this.ConnectionContext.SqlConnectionObject.Database
49
- }
50
-
51
- if (-not $Database) {
52
- $Database = $this.ConnectionContext.DatabaseName
53
- }
44
+ try {
45
+ if ($Database) {
46
+ $dataSet = $this.Databases[$Database].ExecuteWithResults($Query)
47
+ } else {
48
+ $dataSet = $this.ConnectionContext.ExecuteWithResults($Query)
54
49
}
55
- if (-not $Database) {
56
- $Database = "master"
50
+ if ($AllTables) {
51
+ $dataSet.Tables
52
+ } else {
53
+ $dataSet.Tables[0]
57
54
}
55
+ } catch {
56
+ $message = ''
57
+ $innerException = $_.Exception.InnerException
58
+ while ($innerException.InnerException) {
59
+ $message += $innerException.Message
60
+ $innerException = $innerException.InnerException
61
+ }
62
+ $message += $innerException.Message
63
+ throw $message
58
64
}
59
- if ($AllTables) { ($this.Databases[$Database].ExecuteWithResults($Query)).Tables }
60
- else { ($this.Databases[$Database].ExecuteWithResults($Query)).Tables[0] }
61
65
</Script >
62
66
</ScriptMethod >
63
67
<ScriptMethod >
64
68
<Name >Invoke</Name >
65
69
<Script >
66
70
param (
67
- $Command,
68
- $Database
71
+ [string] $Command,
72
+ [string] $Database
69
73
)
70
74
71
- if (-not $Database) {
72
- if ($this.ConnectionContext.DatabaseEngineType -eq "SqlAzureDatabase") {
73
- $Database = $this.ConnectionContext.ExecuteScalar("select db_name()")
74
- if (-not $Database) {
75
- $Database = $this.ConnectionContext.SqlConnectionObject.Database
76
- }
77
-
78
- if (-not $Database) {
79
- $Database = $this.ConnectionContext.DatabaseName
80
- }
75
+ try {
76
+ if ($Database) {
77
+ $this.Databases[$Database].ExecuteNonQuery($Command)
78
+ } else {
79
+ $this.ConnectionContext.ExecuteNonQuery($Command)
81
80
}
82
- if (-not $Database) {
83
- $Database = "master"
81
+ } catch {
82
+ $message = ''
83
+ $innerException = $_.Exception.InnerException
84
+ while ($innerException.InnerException) {
85
+ $message += $innerException.Message
86
+ $innerException = $innerException.InnerException
84
87
}
88
+ $message += $innerException.Message
89
+ throw $message
85
90
}
86
- $this.Databases[$Database].ExecuteNonQuery($Command)
87
91
</Script >
88
92
</ScriptMethod >
89
93
</Members >
0 commit comments