Problem in accessing name of database in SQL Server Profiler - sql-server-profiler

I want to find which database is querying from, here is my output:
EXEC sp_example #stat = N'SELECT stat FROM [dbo].[statsUSers] AS [UserStats];
What I want is like this:
EXEC sp_example #stat=N'SELECT stat FROM [MyOwnDataBase].[statsUSers] AS [UserStats];
I've already tried this tip:
SQL Server Profiler - how do I find which database is being connected?
but still it's [dbo] and not showing the name of the database.
Question
How can I access name of database?
I don't want [dbo] changes to something meaningless - I want the actual name of database.

When creating the trace, you can select Show all columns, which will then display the DatabaseID and DatabaseName columns.
Note that dbo is the schema name, not the database name. There is no option to capture the default schema of the user, this is the one they would refer to if accessing a table like SELECT * FROM table. To capture the default schema you would instead have to capture the username then work out what the user's default schema is.
I would advise you to move away from the essentially deprecated Profiler, to Extended EVents, which provides far more information and puts far less load on the server.
In Extended Events, you can add the database_name also.

Related

How to analyze oracle dump file

I need to analyze a large Oracle DMP file. So far, I have no experience with Oracle.
I know that the database contains information about certain people, for example a person with the name Smith.
I don't know how the database is structured (which table contains which information, are there triggers, ...).
As long as I don't know which tables I have to search, the best way I have found to work with the database files is to use grep.
This way, I can at least verify that the database really does contain the name "Smith".
Ultimately, I would like to have an SQL dump that can be viewed, filtered and understood in a text editor.
The DMP file was created with
expdp system / [PW] directory = [expdp_dir] dumpfile = [dumpfile.dmp] full = yes logfile = [logfile.log] reuse_dumpfiles = y
I know that the name Smith occurs often in the Database. Running grep -ai smith dumpfile.dmp returns many hits.
To analyze the database further I installed oracle-database and sqldeveloper-20.2.0.175.1842-x64. I imported the DMP file with
impdp USERID = system / [PW] FULL = y FILE = [dumpfile.dmp]
The folder C:\app\[user]\oradata\orcl now contains the files SYSAUX01.DBF and SYSTEM01.DBF, among others.
I suspect that these are the database files.
The command grep -ai smith * .DBF does not return any hits.
Either the files SYSAUX01.DBF and SYSTEM01.DBF are not the databases or something did not work on the import.
Using the SQL developer, I log in with the following data:
User: system
Password: [PW] (= PW from the expdp command)
SDI: orcl
In SQL developer, I do not find Smith. SQL developer displays many tables, most of which seem
to be empty and none of which I understand. I suspect that these tables are not the tables I am looking for. Perhaps I need to log in a different way (different user, different SDI?).
I tried to export the database to an SQL dump file, trying out various options that SQL developer provides,
but the result does not contain the string "Smith".
Something is not right:
Import is faulty
wrong SDI
Export is faulty
anything else
What might have gone wrong along the way?
You have a lot misconceptions in your question.
Oracle Datapump is a database utility designed for exporting and importing. But the content, either is DDL commands ( as create table, create index ) or data from the tables, is stored as binary, so you can't check the contents of those files. There are options to extract the DDL commands from the dumpfile and put it into a script.
The datafiles you are mentioned are part of the database itself, they have nothing to do with datapump. Do not touch those files
I don't know what you mean by "Smith" , if you mean an schema, after importing make a select over dba_users looking for the field username = 'SMITH'
If you mean looking for "Smith" as part of any of those tables, you will have to look in any single table of the database ( except the ones of schemas belonging to Oracle ) and for each field that is a string
SDI does not mean anything. I guess you meant SID or Oracle System ID, an unique identifier to identify a database in a specific environment
There is nothing wrong. The problem I believe is that you don't exactly know what you are looking for.
Check this
A user/schema with name SMITH
SQL> SELECT USERNAME FROM DBA_USERS WHERE USERNAME = 'SMITH' ;
A table which name contains the word SMITH ( unlikely )
SQL> SELECT TABLE_NAME FROM DBA_TABLES WHERE TABLE_NAME LIKE '%SMITH%' ;

is there any way to know the oracle database instance failure count

I am working on Oracle database, I have to know about instance failure, also I need to save instance failure count in a file, if there is any command to do this? where can I get the information of the instance failure ? any logs ?
I am new to Oracle, I don't know about what are the commands used to get instance failure.
Try this query to get the instance count in oracle,
SELECT COUNT(STATUS) INSTANCES_RUNNING,
sys_context('USERENV', 'INSTANCE_NAME') "I'm logged in"
FROM GV$INSTANCE
WHERE STATUS='OPEN'
GROUP BY STATUS
Oracle contains a set of underlying views that are maintained by the database server. These views are called dynamic performance views.
The dynamic performance views are V$ Views and GV$ Views.
In oracle RAC I think the following query helps,
select * from v$active_instances

Cannot update Oracle view from JDBC

Overview: Need to read row from Oracle view and create a Notes document, save document, then write Document Unique ID back to Oracle.
I am able to read connect and read data no problem. I am using a type 4 connection connecting to an Oracle 11 database. The Oracle view is setup to allow Updating. The view has nothing in it that is outline here: In Oracle, is it possible to INSERT or UPDATE a record through a view?
*With the same username and password, you are able to successfully update view by typing in SQL statement.
*Tried using conn.setAutoCommit(false); This had no effect.
*Verified that the result set was updatable (1008)
*User has been given full DBA access (temporarily)
*I have tried every possible combination of the first parameter in the createStatement method
...
Statement statement = conn.createStatement(ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_UPDATABLE);
ResultSet rs = statement.executeQuery(fetch);
...
String UNID = doc.getUniversalID(); //gets unique id from saved Notes Document
System.out.println("This is what to write to Oracle:" + UNID);
System.out.println("is updatable=1008, not updatable=1007 value is:" + rs.getConcurrency());
System.out.println("is Result Set Closed:" + rs.isClosed());
rs.updateString("NOTES_DOC_ID", UNID);
System.out.println("got past updating NOTES_DOC_ID column");
rs.updateRow(); //fails here
Here is the error from console:
This is what to write to Oracle:BF8091259610C61B87257B16005C14FB
is updatable=1008, not updatable=1007 value is:1008
is Result Set Closed:false
got past updating NOTES_DOC_ID column
java.security.AccessControlException: Access denied (java.lang.RuntimePermission exitVM.0)
Prior to asking for the user to have DBA access I would get a
java.sql.SQLSyntaxErrorException: ORA-01031: insufficient privileges
I think this a big clue. My DBA doesn't know what further access to give me.
The DBA is wanting me to start using ref cursors, which is fine, but I suspect there is some kind of security setting for JDBC access that is tripping me up, and I want to explore that first. If there is a security issue, then I don't think changing the way I read the rows is going to make a difference. Most of all the documentation on how to do this was obtained from Oracle's website, as well as this site.
I am going to answer my question and explain how I got past this roadblock. In the end, I basically did what 'a_horse_with_no_name' suggested.
Instead of using the resultSet cursor or a ref cursor to perform the update, I was able to use a plain UPDATE statement. This was possible, because I was able to convince the DBA to create a column for a unique identifier. We could never get around the exceptions caused by the updateRow() method of the resultSet. Prior to him adding the unique identifier, there was not a key in which to reliably use the UPDATE statement.
Here is the code where updateSQL is a string holding the update SQL statement:
updateResultInt = updateStatement.executeUpdate(updateSQL);
It returns a 1 if successful.
One word of caution, if you are using a tools like TOra or sql plus to check your update statements, you have to remember to manually commit them. If you don't your java agent will hang when trying to run it. Here is an good reference that helped me with that issue: SQL Update hangs Java program
Thanks to those who commented!

query from different oracle connections in sqldeveloper

I have 2 connections with different tables in sqldeveloper.
let's say:
ConnectionA with tables: A,B,C
ConnectionB with tables: D,E,F
Now I want to have a query that looks like this:
select aa.name,dd.id
from A aa,D dd;
How can i do this?
If you want to query objects in two different databases using a single SQL statement, you would need to create a database link between the two databases. A database link is an object that resides in the database and is independent of the query tool. In database A, for example, you could create the database link
CREATE DATABASE LINK to_b
CONNECT TO username IDENTIFIED BY password
USING tns_alias_on_a_pointing_to_b
And then when you connect to A, you could do something like
SELECT aa.name, dd.id
FROM a aa,
d#to_b dd
WHERE aa.some_key = dd.some_key
Apparently TOAD Data Point supports Cross-Connection Queries , see:
http://dev.toadfordataanalyst.com/webhelp/Content/Query_Builder/Create_CrossConnection_Queries.htm
Also Oracle SQL Developer seems to support something similar. (see this blog post: Cross Connection Queries)
I found this helpful and to the point of the OP question for Oracle 11g rel 2 and later: http://www.dba-oracle.com/t_how_create_database_link.htm . Basically, right-click on the connection in the Connections pane in SQL Developer, click Properties, and you get the hostname, port, and service name that you can plug into the "USING" part of the CREATE DATABASE LINK statement. Whether you put in Service Name or SID I assume depends on which you used in your connection. example:
create public database link
mylink
connect to
remote_username
identified by
mypassword
using 'myserver:1521/MYSID';

Run a Query from Linked Server (Oracle) in SQL Server2008 R2

I have the linked server set up in SQL Server 2008. But I could not run any query against the linked server.
I tried to run this simple command but it's not working
SELECT * FROM MYSERVER..ALANH.TEMP_UPDATE1
This is the error I got when I run the above command.
Msg 7399, Level 16, State 1, Line 1
The OLE DB provider "OraOLEDB.Oracle" for linked server "MYSERVER" reported an error. The provider did not give any information about the error.
Msg 7312, Level 16, State 1, Line 1
Invalid use of schema or catalog for OLE DB provider "OraOLEDB.Oracle" for linked server "MYSERVER". A four-part name was supplied, but the provider does not expose the necessary interfaces to use a catalog or schema.
Could anyone help me to connect to the OracleLinkedServer? Thanks very much.
you can be that way too:
**SELECT * FROM OPENQUERY(MYSERVER, 'SELECT * FROM ALANH.TEMP_UPDATE1')**
You can write the query like this:
select * FROM [MYSERVER]..[ALANH].[TEMP_UPDATE1]
Important: In this case, the fully qualified table name must be written in upper case.
You might try the fix from this article.
Also, this could be a problem with naming. From an MS KB article
If you receive these error messages, a table may be missing in the
Oracle schema or you may not have permissions on that table. Verify
that the schema name has been typed by using uppercase. The
alphabetical case of the table and of the columns should be as
specified in the Oracle system tables.
On the Oracle side, a table or a column that is created without double
quotation marks is stored in uppercase. If the table or the column is
enclosed in double quotation marks, the table or the column is stored
as is.
First make sure the tnsping utility works from client server, then use the below string in linked server database source setup
host[:port]/service_name
Check this link for more details :
http://www.oracledistilled.com/oracle-database/oracle-net/using-easy-connect-ezconnect-naming-method-to-connect-to-oracle-databases/
Try something like this:
SELECT * FROM ALL_TABLES#"SOME.SERVER.NAME";
In this case I'm selecting ALL_TABLES from a linked server called SOME.SERVER.NAME.
Richard's post above was critical.
I am using v12 ODP.NET odbc drivers and had to ensure that "Zero Level Only" was NOT checked and that the names supplied for table and schema were the correct case. All of the schemas and tables I access are uppercase only.
Use the query below to determine what the correct table name is, though you will have to supply the schema name in the correct case for the query to work. Try all uppercase, try all lowercase, try mixed case, or better yet get the actual name from the dba (I've heard that only table/schema names that are "" quoted will be allowed mixed case, otherwise in oracle it's all uppercase.)
sp_tables_ex #table_server=InsertLinkedServerHere, #table_schema=InsertSchemaNameHere

Resources