Hello i got a program that restores databases from .bak files and it works fine when there is no database with that name but when i try it when there already is an database with the same name i get this error
Could not send response error 500: javax.servlet.ServletException: javax.servlet.ServletException: java.lang.RuntimeException: java.lang.IllegalStateException: org.springframework.dao.TransientDataAccessResourceException: StatementCallback; SQL [IF EXISTS (SELECT name FROM sys.databases WHERE name = N'utv_johan')
BEGIN
ALTER DATABASE utv_johan SET SINGLE_USER WITH ROLLBACK IMMEDIATE;
drop database utv_johan;
END
]; ALTER DATABASE failed because a lock could not be placed on database 'utv_johan'.
I am doing a new version of an old app and on the old one it works fine with the statement and all. and i use the same code for this but with a new React GUI. Anyone know how this error occurs and how to fix it? If you need more info feel free to ask! i saw someone here with same error when he were trying to take down his sql server. But i have done nothing with the database same calls as the old version.
Its seem as after some more testing that it sometimes works and throws no error at all.
It looks like your DEADLOCK_PRIORITY is equal to or less than another session and thus, you aren't able to ROLLBACK their transaction. You can explicitly set your priority and see if this resolves it.
USE [MASTER]
SET DEADLOCK_PRIORITY 10
ALTER DATABASE utv_johan SET SINGLE_USER WITH ROLLBACK IMMEDIATE;
DROP DATABASE utv_johan;
I receive for a lot of queries on my FTS indexes this exception:
com.google.appengine.api.search.SearchException >>
Temporary search service error
com.google.appengine.api.search.IndexImpl$4.convertException(IndexImpl.java:354)
com.google.appengine.api.utils.FutureWrapper.get(FutureWrapper.java:97)
com.google.appengine.api.search.FutureHelper.getInternal(FutureHelper.java:73)
com.google.appengine.api.search.FutureHelper.quietGet(FutureHelper.java:32)
com.google.appengine.api.search.IndexImpl.search(IndexImpl.java:505)
This error appears for some period of time for certain queries, then it works for that query, but fails for others.
Can you help me with this?
I can provide additional data on request!
I have a java web application that uses the next function to execute a stored procedure, it connects to SQL Server 2008:
Class.forName(sDriver_Reportes);
conn = DriverManager.getConnection(sDB_URL, sUSER, sPASS);
sQuery = "{call procGetResult(?)}";
proc = conn.prepareCall(sQuery);
proc.setString("pDate", sDate);
proc.execute();
rs = proc.getResultSet();
but it takes about 7 minutes to return the resultset, if I execute the sp it takes just 10 seconds to show the result.
I were looking for some similar case but only found post about parameter sniffing and connection pool but anyone seems to be like mi case because the sp is running fast, could you give me some info about where else to look about this issue.
Thank you in advance.
It seems to be a problem of SQL Server Parameter Sniffing. The first thing you need to check is the execution plan for your stored procedure.You can view it using the following icon in SQL Server Management Studio:
Now being exposed to the problem here are a few methods to address it:
Create SQL Server Stored Procedures using the WITH RECOMPILE Option
Use the SQL Server Hint OPTION (RECOMPILE) Use the SQL Server Hint
OPTION (OPTIMIZE FOR) Use Dummy Variables on SQL Server Stored
Procedures Disable SQL Server Parameter Sniffing at the Instance
Level Disable Parameter Sniffing for a Specific SQL Server Query
For implementation and better understanding you can refer the below link :
https://www.mssqltips.com/sqlservertip/3257/different-approaches-to-correct-sql-server-parameter-sniffing/
The purpose is to send extra information to triggers like current user id from a web application. Since a connection pool is used, and same user id is used for all connections how do I pass the original web user id to trigger? It is a java based application.
If you can't touch the application code and the application itself does not pass this information to the database already, you're at an impasse. The only way to make that information available to back-end code is for the middle tier to pass it in.
Oracle provides a number of ways for applications to pass information from the middle-tier to the back end but the application has to be built to take advantage of them. The DBMS_APPLICATION_INFO package, for example, has a set_client_info procedure that allows the middle tier to pass in the name of the middle tier user that your back end trigger could query. You can also use Oracle contexts if you want a more general mechanism. Either of these approaches, however, realistically require that the Java application be written to pass this information to the back-end when connections are retrieved from the connection pool.
You can make use of proxy authentication to identify the users even with a ConnectionPool.
An example:
me#XE> #man proxy
[ P R O X Y A U T H E N T I C A T I O N ]
drop user application_user
drop user end_user
-- let's create the application user which all users
-- need to connect through.
-- This user is meant as the middle-tier-user in a
-- multi-tier setup.
create user application_user identified by application_user
-- create an end-user
create user end_user identified by end_user
quota unlimited on users
grant create session, create table to end_user
-- this is the clause to grant access to end_user.
alter user end_user grant connect through application_user
-- now, we can connect WITHOUT PASSWORD!
#connect application_user[end_user]/application_user
-- this should display "END_USER"
select user from dual
-- this should display "APPLICATION_USER"
column proxy_user format a30
select sys_context('userenv', 'proxy_user') proxy_user from dual
http://blogs.oracle.com/jheadstart/entry/using_proxy_authentication
When my application connects to an Oracle database I want to be able to see by looking at the active sessions in the database that it is connected. Currently it identifies itself as "JDBC Thin Client" because that's the driver that I'm using, but other Java based applications that I have are somehow able to set this value to something more meaningful, like "SQL Developer". I thought it was a property of the Connection or the OracleDataSource, but I've not managed to find one that does the trick. Is this possible? In case it matters, I'm using Java 1.5, with Oracle 10g and the 10g thin driver.
java.util.Properties props = new java.util.Properties();
props.setProperty("password","mypassword");
props.setProperty("user","myusername");
props.put("v$session.osuser", System.getProperty("user.name").toString());
props.put("v$session.machine", InetAddress.getLocalHost().getCanonicalHostName());
props.put("v$session.program", "My Program Name");
DriverManager.registerDriver (new oracle.jdbc.OracleDriver());
Connection conn=
DriverManager.getConnection("jdbc:oracle:thin:#myhostname:1521:mysid", props);
SQL>select username,osuser,program,machine
from v$session
where username = 'ROB';
USERNAME OSUSER PROGRAM MACHINE
--------- ----------- ------------------ -----------
ROB rmerkw My Program Name machine
At application level you can use the following methods to set client_info, module and action in v$session:
dbms_application_info.set_client_info
dbms_application_info.set_module
dbms_application_info.set_action
There is also an Oracle function:
dbms_application_info.set_client_info('Client Info');
which sets the ClientInfo column in v$session.
This might be useful if you only have access to the Connection rather than the underlying DataSource or DriverManager.
Since oracle jdbc 12.1 you can set some client-info values via jdbc api, i.e. you can do
connection.setClientInfo("OCSID.CLIENTID", "MyClientId");
for properties OCSID...
ACTION, CLIENTID, ECID, MODULE, SEQUENCE_NUMBER and DBOP
See https://docs.oracle.com/database/121/JJDBC/jdbcvers.htm#JJDBC29006
Setting PROGRAM doesn't work this way, you can do that as described in the accepted answer or somewhat easier by setting the System property "oracle.jdbc.v$session.program".
You need to define the connection property v$session.program in your data source, in such a way that that property will be added to each connection. How you do that depends on your data source implementation. The value you set the property to will appear in oracle's active session table.
Starting with 12.1 the setEndToEndMetrics is deprecated, you may use setClientInfo
see the documentation for 12.2 here
Here a snippet of the usage
// "conn" is an instance of java.sql.Connection:
conn.setClientInfo("OCSID.CLIENTID", "clientID");
conn.setClientInfo("OCSID.MODULE", "myModule");
conn.setClientInfo("OCSID.ACTION", "myAction");
You may see the setting in V$SESSION with this query of the relevant session
select MODULE, ACTION, CLIENT_IDENTIFIER from v$session where ...
but only after a next statement is executed with this connection. The call of setClientInfo triggers no extra roundtrip this information is passed whit the next call.
Note also that you must use the Oracle (unwrapped) conenction - Check this for reference.