Use of xml.modify from nested XML - SSRS Subscription Table - sql-server

I'm trying to do a bulk update on email addresses stored in the ExtensionSettings columns from the Subscription table in SSRS database.
I'm a bit lost on how to update the TO and CC values from the XML column.
<ParameterValues>
<ParameterValue>
<Name>TO</Name>
<Value>Jon#yahoo.com</Value>
</ParameterValue>
<ParameterValue>
<Name>CC</Name>
<Value>Sarah#yahoo.com</Value>
</ParameterValue>
<ParameterValue>
<Name>BCC</Name>
<Value />
</ParameterValue>
<ParameterValue>
<Name>ReplyTo</Name>
<Value />
</ParameterValue>
<ParameterValue>
<Name>Subject</Name>
<Value>#ReportName was executed at #ExecutionTime</Value>
</ParameterValue>
<ParameterValue>
<Name>Comment</Name>
<Value />
</ParameterValue>
<ParameterValue>
<Name>Priority</Name>
<Value>NORMAL</Value>
</ParameterValue>
<ParameterValue>
<Name>IncludeLink</Name>
<Value>True</Value>
</ParameterValue>
<ParameterValue>
<Name>IncludeReport</Name>
<Value>True</Value>
</ParameterValue>
<ParameterValue>
<Name>RenderFormat</Name>
<Value>MHTML</Value>
</ParameterValue>
</ParameterValues>
I got some reference but still lost
https://www.sqlshack.com/different-ways-to-update-xml-using-xquery-in-sql-server/
Basically, I just want to update those properties with < Name >TO</ Name> and < Name >CC</ Name> and update the values to "Test#domain.com"
UPDATE user_details
SET ExtensionSettings.modify('replace value of (/ParameterValues/ParameterValue/Value/text()) with "Test#domain.com"')
WHERE SubscriptionID='2B0080DE-14FA-4A3D-8AEF-14A9238E7841'

The XML.modify() method will only allow you to perform a single modification at a time. Since you want to modify two values you need to execute two UDPATE statements:
UPDATE user_details
SET ExtensionSettings.modify('
replace value of (/ParameterValues/ParameterValue[Name/text()="TO"]/Value/text())[1]
with "Test#domain.com"
')
WHERE SubscriptionID='2B0080DE-14FA-4A3D-8AEF-14A9238E7841';
UPDATE user_details
SET ExtensionSettings.modify('
replace value of (/ParameterValues/ParameterValue[Name/text()="CC"]/Value/text())[1]
with "Test#domain.com"
')
WHERE SubscriptionID='2B0080DE-14FA-4A3D-8AEF-14A9238E7841';
Selecting the resultant XML will return:
<ParameterValues>
<ParameterValue>
<Name>TO</Name>
<Value>Test#domain.com</Value>
</ParameterValue>
<ParameterValue>
<Name>CC</Name>
<Value>Test#domain.com</Value>
</ParameterValue>
<ParameterValue>
<Name>BCC</Name>
<Value />
</ParameterValue>
<ParameterValue>
<Name>ReplyTo</Name>
<Value />
</ParameterValue>
<ParameterValue>
<Name>Subject</Name>
<Value>#ReportName was executed at #ExecutionTime</Value>
</ParameterValue>
<ParameterValue>
<Name>Comment</Name>
<Value />
</ParameterValue>
<ParameterValue>
<Name>Priority</Name>
<Value>NORMAL</Value>
</ParameterValue>
<ParameterValue>
<Name>IncludeLink</Name>
<Value>True</Value>
</ParameterValue>
<ParameterValue>
<Name>IncludeReport</Name>
<Value>True</Value>
</ParameterValue>
<ParameterValue>
<Name>RenderFormat</Name>
<Value>MHTML</Value>
</ParameterValue>
</ParameterValues>

Related

PowerShell Exception calling "Open" with "0" argument(s): "ORA-12537: Network Session: End of file"

I am getting this error in
PowerShell
I am trying to stablish a connection to an Oracle Database and see if I can get any data in return. I found some code and put this together. I see most people use the "connection.open() to stablish a connection to the database so that is the norm but I am not sure why I am getting this errors any ideas?
PS SQLSERVER:\>
Exception calling "Open" with "0" argument(s): "ORA-12537: Network Session: End of file"
At line:8 char:1
+ $connection.open()
+ ~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [], MethodInvocationException
+ FullyQualifiedErrorId : OracleException
Exception calling "ExecuteReader" with "0" argument(s): "Connection must be open for this operation"
..
..
..
PS SQLSERVER:\>
here is my code
Add-Type -Path "C:\Oracle\product\12.2.0\client_1\ODP.NET\managed\common\Oracle.ManagedDataAccess.dll"
$username = Read-Host -Prompt "Enter database username"
$password = Read-Host -Prompt "Enter database password"
$datasource = Read-Host -Prompt "Enter database TNS name"
$query = "SELECT SYSDATE FROM DUAL"
$connectionString = 'User Id=' + $username + ';Password=' + $password + ';Data Source=' + $datasource
$connection = New-Object Oracle.ManagedDataAccess.Client.OracleConnection($connectionString)
$connection.open()
$command=$connection.CreateCommand()
$command.CommandText=$query
$reader=$command.ExecuteReader()
while ($reader.Read()) {
$reader.GetString(1) + ', ' + $reader.GetString(0)
}
$connection.Close()
Try to use System.Data.OracleClient instead of Oracle.ManagedDataAccess.dll. You have to have the Oracle Client installed on the machine you are executing the script.

Exception calling ExecuteNonQuery in PowerShell to Azure PaaS database

I'm having an odd issue using the System.Data.SqlClient in PowerShell. The following works, using MSSMS:
INSERT INTO [dbo].[secDb_AADDevices]
([objectGuid]
,[displayName]
,[deviceGuid])
VALUES
('test','here','now')
But when doing this in PowerShell:
$sqlQuery = "INSERT INTO secDb_AADDevices ('objectGuid','displayName','deviceGuid') VALUES('test','here','now')"
$sqlCmd=new-object system.Data.SqlClient.SqlCommand($sqlQuery, $sqlConn)
$sqlCmd.ExecuteNonQuery()
It fails;
Exception calling "ExecuteNonQuery" with "0" argument(s): "Invalid column name 'objectGuid'.
Invalid column name 'displayName'.
Invalid column name 'deviceGuid'."
At line:4 char:1
+ $sqlCmd.ExecuteNonQuery()
+ ~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [], MethodInvocationException
+ FullyQualifiedErrorId : SqlException
The column types in MSSQL are nvarchar(50) not null.
I've simplified it as much as possible to reduce complexity while debugging, will parameterize when this part works.
I've triple-verified that MSSQL and PowerShell ($sqlConn object) are connected to the same server and database instance, using the exact same user.

FAILED: dbconnection com.microsoft.sqlserver.jdbc.SQLServerException: Could not find stored procedure while executing SQL query through Selenium

I have made the sql connection , and fetching the query from excel sheet.
and after establishing db cooncetion, calling:
result rs= st.executeQuery(query)
statement is showing error as couldnot find storedprocedure.
Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
String querypath = "C:/Users/svhirekalmath/eclipse-workspace/NepalBITestNg/queries/queries.xlsx";
FileInputStream queryFile = new FileInputStream(new File(querypath));
XSSFWorkbook queryBook = new XSSFWorkbook(queryFile);
Sheet querySheet=queryBook.getSheet("Sheet1");
String query=ReusableFunctions.getPropertiesValue("COMPANY"); // fetching query
queryBook.close();
Connection con = DriverManager.getConnection("jdbc:sqlserver://cdtssql879d;database=NepalBI_1","SNABI_user","SNABI#123");
Statement st = con.createStatement();
ResultSet rs = st.executeQuery(query); // getting error at this line
Error:
FAILED: dbconnection
com.microsoft.sqlserver.jdbc.SQLServerException: Could not find stored procedure 'applicationPassword'.
at com.microsoft.sqlserver.jdbc.SQLServerException.makeFromDatabaseError(SQLServerException.java:196)
at com.microsoft.sqlserver.jdbc.SQLServerStatement.getNextResult(SQLServerStatement.java:1454)
at com.microsoft.sqlserver.jdbc.SQLServerStatement.doExecuteStatement(SQLServerStatement.java:786)
at com.microsoft.sqlserver.jdbc.SQLServerStatement$StmtExecCmd.doExecute(SQLServerStatement.java:685)
at com.microsoft.sqlserver.jdbc.TDSCommand.execute(IOBuffer.java:4026)
at com.microsoft.sqlserver.jdbc.SQLServerConnection.executeCommand(SQLServerConnection.java:1416)
at com.microsoft.sqlserver.jdbc.SQLServerStatement.executeCommand(SQLServerStatement.java:185)
at com.microsoft.sqlserver.jdbc.SQLServerStatement.executeStatement(SQLServerStatement.java:160)
at com.microsoft.sqlserver.jdbc.SQLServerStatement.executeQuery(SQLServerStatement.java:620)
at marketoverview.MarketOverviewTest.dbconnection(MarketOverviewTest.java:153)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.testng.internal.MethodInvocationHelper.invokeMethod(MethodInvocationHelper.java:124)
at org.testng.internal.Invoker.invokeMethod(Invoker.java:583)
at org.testng.internal.Invoker.invokeTestMethod(Invoker.java:719)
at org.testng.internal.Invoker.invokeTestMethods(Invoker.java:989)
at org.testng.internal.TestMethodWorker.invokeTestMethods(TestMethodWorker.java:125)
at org.testng.internal.TestMethodWorker.run(TestMethodWorker.java:109)
at org.testng.TestRunner.privateRun(TestRunner.java:648)
at org.testng.TestRunner.run(TestRunner.java:505)
at org.testng.SuiteRunner.runTest(SuiteRunner.java:455)
at org.testng.SuiteRunner.runSequentially(SuiteRunner.java:450)
at org.testng.SuiteRunner.privateRun(SuiteRunner.java:415)
at org.testng.SuiteRunner.run(SuiteRunner.java:364)
at org.testng.SuiteRunnerWorker.runSuite(SuiteRunnerWorker.java:52)
at org.testng.SuiteRunnerWorker.run(SuiteRunnerWorker.java:84)
at org.testng.TestNG.runSuitesSequentially(TestNG.java:1208)
at org.testng.TestNG.runSuitesLocally(TestNG.java:1137)
at org.testng.TestNG.runSuites(TestNG.java:1049)
at org.testng.TestNG.run(TestNG.java:1017)
at org.testng.remote.AbstractRemoteTestNG.run(AbstractRemoteTestNG.java:115)
at org.testng.remote.RemoteTestNG.initAndRun(RemoteTestNG.java:251)
at org.testng.remote.RemoteTestNG.main(RemoteTestNG.java:77)
This error message...
FAILED: dbconnection
com.microsoft.sqlserver.jdbc.SQLServerException: Could not find stored procedure 'applicationPassword'.
...implies that there was an error while your program tried to execute the query.
A bit more details about the line:
String query=ReusableFunctions.getPropertiesValue("COMPANY");
would have helped us to analyze the issue in a better way. However, the standard structure of a pl/sql statement to be executed through Selenium is as follows:
String query = "select * from seleniumuser"
So ideally,
String query=ReusableFunctions.getPropertiesValue("COMPANY");
System.out.println(query);
should print something similar to:
select * from seleniumuser
Additionally, the instance of the Connection should have included the port number as follows:
Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/selenium","root","root");
The port number seems to be missing from your code trial:
Connection con = DriverManager.getConnection("jdbc:sqlserver://cdtssql879d;database=NepalBI_1","SNABI_user","SNABI#123");
Note: #JimEvans in his comment further clarified that Selenium has any support for executing SQL queries is misleading. It’s standard Java library execution, and has absolutely nothing to do with Selenium

Tomcat / Jdbc / The statement did not return a result set

We are using JDBC to exec a stored procedure (SQL Server) returning resultset.
The connection is retrieve from Tomcat pooling.
It's work fine.
But, after a while (several days or weeks after application start), we have the following error on the executeQuery from PreparedStatement :
com.microsoft.sqlserver.jdbc.SQLServerException: The statement did not return a result set.
at com.microsoft.sqlserver.jdbc.SQLServerException.makeFromDriverError(SQLServerException.java:190)
at com.microsoft.sqlserver.jdbc.SQLServerPreparedStatement.doExecutePreparedStatement(SQLServerPreparedStatement.java:408)
at com.microsoft.sqlserver.jdbc.SQLServerPreparedStatement$PrepStmtExecCmd.doExecute(SQLServerPreparedStatement.java:350)
at com.microsoft.sqlserver.jdbc.TDSCommand.execute(IOBuffer.java:5696)
at com.microsoft.sqlserver.jdbc.SQLServerConnection.executeCommand(SQLServerConnection.java:1715)
at com.microsoft.sqlserver.jdbc.SQLServerStatement.executeCommand(SQLServerStatement.java:180)
at com.microsoft.sqlserver.jdbc.SQLServerStatement.executeStatement(SQLServerStatement.java:155)
at com.microsoft.sqlserver.jdbc.SQLServerPreparedStatement.executeQuery(SQLServerPreparedStatement.java:285)
at sun.reflect.GeneratedMethodAccessor91.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.apache.tomcat.jdbc.pool.interceptor.AbstractQueryReport$StatementProxy.invoke(AbstractQueryReport.java:235)
at com.sun.proxy.$Proxy5.executeQuery(Unknown Source)
Exception appended on executeQuery (see beelow)
final PreparedStatement stmt = super.getConnection().prepareStatement("exec sp_storeprocedure ?, ?");
stmt.setString(1, "value1");
stmt.setString(2, "value2");
ResultSet rs = stmt.executeQuery();

Using REPL.bat to find and replace when bracket '(' is present in phrase being replaced

Trying to use dbenham's REPL.bat to find and replace a phrase which contains a bracket '('
Need to replace (local) with 192.168.1.1 from the below string inside of an XML.
<add name="JobRepository" connectionString="Data Source=(local);Connection Timeout=180;Integrated Security=SSPI;Initial Catalog=JobRepositorydb"
Using type input.file |repl "(local)" "192.168.1.1" >output.file
Produces:
<add name="JobRepository" connectionString="Data Source=(192.168.1.1);Connection Timeout=180;Integrated Security=SSPI;Initial Catalog=JobRepositorydb"
But I need:
<add name="JobRepository" connectionString="Data Source=192.168.1.1;Connection Timeout=180;Integrated Security=SSPI;Initial Catalog=JobRepositorydb"
type input.file |repl "(local)" "192.168.1.1" L >output.file
You need to indicate that the search string is a literal and not a regular expression.

Resources