PRAGMA foreign_keys = ON doesn't take effect? - visual-studio-2010

This is kind of the most annoying thing I've ever worked with. As I understand, when opening a new Query Window, a new connection is created, but in SQLite query window (I'm using Visual Studio integrated Designer for SQLite), it seems to be created every time you click Execute (a red !) button. And the PRAGMA foreign_keys = ON seems to take effect only in a session of connection (means that, after connection is closed, it turns to 0/OFF). If I'm wrong please explain to me why this happens:
-> First, I right-click on the SQLite [My database] (right under the Data Connections node in Server Explorer window in Visual Studio 2010) -> select New Query -> start typing PRAGMA foreign_keys -> shows result: 0 -> try turning it on by PRAGMA foreign_keys = ON -> check if it is ON by PRAGMA foreign_keys -> Still shows result: 0 =>>>> What???
That means I can't turn it on, and I can't benefit from Foreign Key Constraint to keep my data integral.
If foreign_keys is some attribute of a database or a table, it should be always ON/1 once I have turned it on. Therefore, I think that 'liquid' stuff is some attribute of Connection. Can't work with it.
Please help...
Thanks!

Related

Sequences (using as ID) issue in Oracle SQL Developer

I am using sequences to create IDs, so while executing insert stored procedure it will create unique value for ID. But after some time it is losing the definition for the sequence.
Not sure why this is happening again and again and how to solve the problem?
I am using Oracle SQL Developer and in the edit table property there is 'Identity Column' setting. See below:
Next step is setting up trigger and sequence:
It was working fine for some time until this property defaulted. Now it is not there anymore:
Still have this trigger and sequence object in the schema and able to setup again but it will break later.
How to avoid this problem in future?
I think it is just a bug/limitation in your client software, Oracle SQL Developer. The "Identity Column" tab is a handy way to create the corresponding sequence and trigger but it doesn't seem to recognise existing elements. I've just verified my own system and that's exactly what happens.
It makes sense, because adding a new sequence and trigger is a pretty straightforward task (all you need is a template) but displaying current sequence is hard given that a trigger can implement any conceivable logic. Surely it could be done but the cost-benefit ratio probably left things this way.
In short, your app is not broken so nothing needs to be fixed on your side.
This is what I received from IT support regarding the issue:
A few possibilities that might cause this:
1 - Another user with limited privileges might be editing the table using SQL Developer. In this case, if this user's privilege is not enough to obtain the sequence and/or trigger information from the database, the tool might leave the fields blank and disable it when table changes are saved.
2 - The objects are being changed or removed outside of SQL Developer, causing it to lose the information. In my tests I noticed that dropping the trigger and recreating it with the same name caused the identity property information to be lost on SQL Developer.
Even being the trigger enabled, and working for inserts it could not retrieve the information.
Then, if I run an alter trigger to enable it (even tough dba_trigger is reporting it as already enabled), SQL Developer will list the information again:
ALTER TRIGGER "AWS"."TABLE1_TRG" ENABLE;
So it looks like there are some issues with the SQL Developer, that is causing this behavior.
Next time it happen, please check if the trigger still exist on the database and is enabled with the query below:
select owner, trigger_name, TRIGGER_TYPE, TRIGGERING_EVENT, TABLE_OWNER, TABLE_NAME, STATUS
from dba_triggers
where trigger_name = 'ENTER_YOUR_TRG_NAME'; --Just change the trigger name in WHERE

How to check existence of a table when create table using GUI

I want to creat a table using GUI in SQL Server 2012, but I can't find anywhere to check existence of a table.
I found solution for my question:
select database click right mouse -> select Task -> Generate Script -> Set Scripting Options-> Advanced-> Change value of "Check for object existence" is True.
In SSRS, expand out the Server; expand out the "Databases" node; expand out your database; expand out "Tables".
Your table will be listed if it's present.

VS2008 SSRS using to query Oracle: How do I stop {oj} for outer Joins?

I am using VS2008 SSRS to query and report a Oracle Database.
Whenever I the query Designer to add an outer join it adds {oj}
e.g.
OJ Added
SELECT A.*,B.*
FROM {oj A LEFT OUTER JOIN B On A.id = B.id}
OJ Not added(How I want it)
SELECT A.*,B.*
FROM A LEFT OUTER JOIN B On A.id = B.id
The only way I can get the query to run is to "Edit as Text..." and remove the {oj...}
Is there any way of stopping Visual Studio 2008 from adding the {oj} when I want an outer join, without having to "Edit as Text"
I assume you have yet to find a solution. I am pretty sure the Oracle driver for SSRS is just plain wrong - there is no problem with SQL Server data sources. I can't believe there aren't more people complaining about it.
It used to work, but used the old style (+) syntax for outer joins, until a year or so ago. I guess at that point there was some update which attempted to change it to the newer syntax, but blew it by including the curly bracket oj, which seems to be the normal syntax for some other sources, but it certainly doesn't work with Oracle.
Yes, of course you can edit it in the text query designer, but if you switch to the graphical designer it immediately re-inserts the curly brackets etc. I like to have the graphical option and it really ought to work!
The issue has been with our suppliers since it first occurred, but they seem quite unable to grasp the problem. They occasionally email me to ask if the problem still exists! I guess they are hoping for a miracle.
MSDN Says that the {oj} syntax should work in Visual Studio. However, it also says that the (+) syntax also works. So you can try-
SELECT A.*,B.*
FROM A , B
WHERE A.id = B.id(+);
While the query below will work in Visual Studio, it will not not work only any Oracle DB Client tools (Toad, SQL Developer, SQL prompt etc.).
SELECT A.*,B.*
FROM {oj A LEFT OUTER JOIN B On A.id = B.id};
One of our guys finally found that if you go into edit text mode you can strip out the {oj and then save the query. (In our case a named query) As long as you don't go back into visual mode in the report designer it will keep the edited query and works fine. However, if you flip over into visual mode the {oj comes back again.

Data got committed in another/same session, cannot update row (Oracle SQL Developer)

I occasionally get this error when i try to update a record through the grid.
One error saving changes to table "SCHEMA"."TABLENAME":
Row 3: Data got committed in another/same session, cannot update row.
Looked up at OTN but no solution yet given.
Tried to disable the option Post edits on row change but still no luck.
There is a known solution for setting the field to NULL through the SQL Worksheet but it's surely a pain.
It could be that your table is created with NOROWDEPENDENCIES so row-level dependency tracking is turned off, and SQL Developer is configured to "Use ORA_ROWSCN for DataEditor insert and update statements".
Either uncheck the ORA_ROWSCN option, or recreate the table with ROWDEPENDENCIES.
Just simply run simple update command and set your cplumn to null. Then try to update with your real value. It will definitely work.
"One error saving changes to table "SCHEMA"."TABLENAME":
Row XX: Data got committed in another/same session, cannot update row."
Got this error with SQL developer when commiting changes in multiple rows,
but not when commiting a single row.
I fixed going to:
Tools menu -> Preferences -> Database -> ObjectViewer
and check: "Post edits on row change"
However, every time I navigate to another row takes some time (less than a second with the DB I am working on).
For what I could understand from other posts the remote DB in my session is being updated (but not comitted to all sessions) every time I change row.
However to commit to all session it is needed to explicitly commit.
Meanwhile I tried, as others suggested, to:
Tools menu -> Preferences -> Database -> ObjectViewer
uncheck "Use ORA_ROWSCN for DataEditor insert and update statements" option
(and also leave uncheck: "Post edits on row change")
This also works, but it is faster.
It guess that now the update is only local. Remote DB is not updated every time I navigate to another row.
It is needed to commit to update remote DB, but now with no errors.
I read that this solution does not worked for all.
It worked in my case with:
SQL developer Version: 17.4.1.054, Build 054.0712
ODAC 12.2c Release 1 and Oracle Developer Tools for Visual Studio (12.2.0.1.0) (32-bit)
(http://www.oracle.com/technetwork/topics/dotnet/utilsoft-086879.html)
Remote DB server version: Oracle Database 11g Release 11.2.0.1.0 - 64bit Production
I ran into this problem as well while running a stored procedure. My solution fell inline with the above answers. Before updating the row that I wanted to the value I wanted, I added an update line that first updated the column to null. The following line then updated the column to the value that I wanted. I did this in addition to unchecking the box for ORA_ROWSCN.
UPDATE TEST_LOCATION SET STATUS = NULL WHERE FULL_NAME = SITE_FULL_NAME;
UPDATE TEST_LOCATION SET STATUS = CAST(STATUS_IN AS INTEGER) WHERE FULL_NAME = SITE_FULL_NAME;

how to debug tsql stored procedure?

How do I debug a tsql Stored procedure. I have tried the following link.
http://msdn.microsoft.com/en-us/library/ms241871(v=vs.80).aspx
But I am unable to hit the break point. Is there a better way to debug. My environment is
Sql Express 2008, Visual Studio 2010
I have found the debugger in SQL Managment studio unreliable as it's so dependant on having the correct permissions on the db server which are not always available.
One alternate method I use is to convert the stored proc into a long query. I start by moving any parameteres to variable declarations and set their values. For examples the following
ALTER PROCEDURE [dbo].[USP_ConvertFinancials] (#EffectiveDate datetime, #UpdatedBy nvarchar(100))
AS
BEGIN
DECLARE #PreviousBusinessDay datetime
would become
DECLARE #Value int,
, #EffectiveDate datetime = '01-Jan-2011
, #UpdatedBy nvarchar(100) = 'System'
This allows me to run the queries within the stored procedure starting from the top. As I move down through the queries, I can check the values of variables by simply selecting them and rerunning the query from the top:
SELECT #Value
I can also comment out the INSERT portion of INSERT-SELECT statements to see what is being inserted into tables and table variables.
The bug in the stored proc usually becomes quite evident using this method. Once I get the query running correctly I can simply copy the code to my proc and recompile.
Good luck!
You can try out Sql Profiler, it does not allows a classical debugging like "break at this point" but gives you an information in great detail about what is going on on each step of a query/SP execution.
Unfortunately Microsoft does not provide it with Express Edition version of Sql Server.
BUT :) There is a good (relatively because it does not provide a lot of filtering criterias which exists in Microsoft's one) and free alternative - SQL Server 2005/2008 Express Profiler.
Debug a stored procedure.
check the logic whether it makes sense or not.
use break point to help find issues.
try to do the modular design as per complex process.
divide the task into multiple simple ones.
use a master stored procedure to take control on the top, and use several child stored procedures to do the job step by step.
As per the optimization, use execution plan, SS Profiler and DTA tools.

Resources