Prior to installation our application checks SQL to make sure it has correct permissions along with various settings. One of those settings is @@OPTION NOCOUNT
.
I cannot seem to figure out for the life of me how to pull this value from the db.
I've tried this. Doesn't matter if NOCOUNT
is on or off, 1 is always returned.
DECLARE @NOCOUNT INT = 1; IF ( (512 & @@OPTIONS) = 512 ) SET @NOCOUNT = 10;
SELECT @NOCOUNT AS NOCOUNT;
I've tried to create a temp table using separate SQL statements in Java and try to pull the value from there with no success. The tables get created just fine, but the value that's always insert in this case is zero.
CREATE TABLE TempNoCount(tNoCount int);
DECLARE @NOCOUNT int = 0;
IF ( (512 & @@OPTIONS) = 512 ) SET @NOCOUNT = 1;
INSERT INTO #TempNoCount (tNoCount) VALUES (@NOCOUNT);
It doesn't matter what I do, I cannot seem to pull the correct value from the database.
Even running this query within Java returns zero.
DECLARE @NOCOUNT INT = 0
IF @@OPTIONS & 512 > 0 SET @NOCOUNT = 2
SELECT @NOCOUNT AS NC
I have also just tried simple querys via java:
SELECT CONVERT(INT,@@OPTIONS & 512) as NOCOUNT;
Still always returns zero regardless if it's on or off.
I've spent a few days on trying to figure out how check if NOCOUNT
is on or off using java application and I've run out of ideas.
The strange part is When I use SQLMgmt studio everything works fine and dandy. Creates insert etc everything works. When I use my java program it doesnt.
Is this i limitation of java? Does MS not want to allow you to pull the @@OPTIONS
using external programs?
I even tried a stored proc. When I call the stored proc it still returns zero even though the result should be 512 when NOCOUNT
is turned....
Any suggestions? I am more then happy to try anything at this point.