|
SET NOCOUNT OFF is working for insert delete update but for select statement it is giving -1 always .
|
|
|
|
|
Member 3487632 wrote: for select statement it is giving -1 always
What a shocker. It is what the doc[^] says: For UPDATE, INSERT, and DELETE statements, the return value is the number of rows affected by the command... For all other types of statements, the return value is -1
|
|
|
|
|
|
Member 3487632 wrote: select statement it is giving -1 always
Why you are checking the SET NOCOUNT in the case of select? Instead of that you can check your result-set rows..
Check your result-set rows for the number of rows selected..
|
|
|
|
|
Based on your other responses.
You have the following code
1. SQL
2. Calling code.
In a previous statement it appears that you cannot modify 2.
So that means you MUST modify 1 such that it returns the value that you want.
Thus for example you can structure a stored proc such that if there are no results, which you check for, then you return zero. (That means you write the code to do just that.)
|
|
|
|
|
How to do SET NOCOUNT ON at database level or at server level
Thanks in advance
|
|
|
|
|
There is no option to turn this on for a particular database on the server. You can turn this off for the whole server <var>Properties > Connections > No Count checkbox</var> .
When I was a coder, we worked on algorithms. Today, we memorize APIs for countless libraries — those libraries have the algorithms - Eric Allman
|
|
|
|
|
Hi Even then rows effected i'm getting -1 in select statement .
What i'm observing is that when i put SET NOCOUNT ON before sql statement even then it is returning -1. I guess it shud return 0 .
I'm having sql server 2005 . Please help.
Thanks
|
|
|
|
|
Hi .
I want to know how can i increase the session existence time in SQL server. I have a software that uses a connection to SQL server . when it remains idle for some minutes then the new session will be created to SQL server from the application side . This produces me me a big problem . Because i use the connection_Id for auditing the user . in my login table i have applicationID that refers to connection_Id in sys.dm_exec_connections .
when the software authenticates the user , It updates the connection_ID in login table and through this column i can get my user's username in my triggers .
here is the problem
when my software becomes idle , then another connection_id is created and i can not trace my user because i can not reach my user in logins table
this is my login table
CREATE TABLE [dbo].[Logins](
[LoginUser] [nvarchar](50) NOT NULL ,
[Password] [nvarchar](50) NOT NULL,
[IsDefaultPassword] [int] NULL,
[AppID] [uniqueidentifier] NULL,
CONSTRAINT [PK_Logins] PRIMARY KEY CLUSTERED
(
[LoginUser] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]
and this is my authenticate procedure
CREATE PROCEDURE [dbo].[Authenticate] (@username nvarchar(30) , @password nvarchar(30))
AS
declare @Authenticated int
set @Authenticated = 0
select @Authenticated = 1
from Logins l
where l.LoginUser =@username and l.Password =@password
if @Authenticated = 1
begin;
declare @AppID uniqueidentifier
select @AppID=p.connection_id from sys.dm_exec_connections p
where p.session_id = @@SPID
update Logins
set AppID = @AppID
where Logins.LoginUser = @username and Logins.Password = @password
end;
select @Authenticated ,@AppID
|
|
|
|
|
yousefshokati wrote: when my software becomes idle , then another connection_id is created
Easiest way out is to not create a new connection, but re-use the existing one. Otherwise, keep the Id around in a variable after your first connect, and pass it as a param on the idle-connection.
Bastard Programmer from Hell
if you can't read my code, try converting it here[^]
|
|
|
|
|
yousefshokati wrote: This produces me me a big problem
Increasing session timeout so you can track users is unlikely to ever be a good idea.
As one example exactly what do you think is going to happen to your system if a 'user' goes on vacation for two weeks but that user remains logged in?
Also it appears that you are attempting to manage permissions by user rather than role. And that is going to become a problem with more than a couple of users.
|
|
|
|
|
I am using this code to save file to MySQL but when I try to open the file after saving it I get an error saying:
Word was unable to read this document. It may be corrupt.
here is the code to write:
file_name = Path.GetFileName(uploadResume.PostedFile.FileName);
file_extension = Path.GetExtension(uploadResume.PostedFile.FileName);
switch (file_extension)
{
case ".pdf": document_type = "application/pdf"; break;
case ".doc": document_type = "application/vnd.ms-word"; break;
case ".docx": document_type = "application/vnd.ms-word"; break;
case ".gif": document_type = "image/gif"; break;
case ".png": document_type = "image/png"; break;
case ".jpg": document_type = "image/jpg"; break;
case ".jpeg": document_type = "image/jpg"; break;
}
int file_size = uploadResume.PostedFile.ContentLength;
byte[] document_binary = new byte[file_size];
uploadResume.PostedFile.InputStream.Read(document_binary, 0, file_size);
and then passing it as parameters:
sql_command.Parameters.AddWithValue("param_resume_format", document_type).MySqlDbType = MySqlDbType.VarChar;
sql_command.Parameters.Add("param_resume_data", MySqlDbType.Blob, file_size).Value = document_binary;
and here is how I am retrieving it:
sql_connection = new MySqlConnection(ConfigurationManager.ConnectionStrings["SQLdb"].ConnectionString);
sql_connection.Open();
sql_command = new MySqlCommand("sp_get_resume_by_id", sql_connection);
sql_command.CommandType = CommandType.StoredProcedure;
sql_command.Parameters.Add("param_resume_id", MySqlDbType.Int32).Value = resume_id;
sql_reader = sql_command.ExecuteReader();
sql_reader.Read();
if (sql_reader.HasRows)
{
file_name = sql_reader["resume_id"].ToString() + sql_reader["resume_ext"].ToString();
byte[] document_binary = (byte[])sql_reader["resume_data"];
FileStream file_stream = new FileStream(@"C:\Temp\" + file_name, FileMode.Create);
file_stream.Write(document_binary, 0, document_binary.Length);
file_stream.Close();
file_stream.Dispose();
txtResume.Visible = true;
}
|
|
|
|
|
I suggest you check out the BINARY datatype[^] from MySql, as a file is not simply a TEXT that you can save.
Bastard Programmer from Hell
if you can't read my code, try converting it here[^]
|
|
|
|
|
so i should not use blob nor LongBlob?
|
|
|
|
|
Should work too, depending on size, but a VARCHAR won't work.
--edit;
Typo, forgotten an "o".
Bastard Programmer from Hell
if you can't read my code, try converting it here[^]
|
|
|
|
|
I tried it with blob, longblob and binary but all giving same problem
|
|
|
|
|
Code & exact error-message - you know the drill
--edit;
I assume that the db-parameter has been set to a binary type, and is no longer the varchar from the first post?
Bastard Programmer from Hell
if you can't read my code, try converting it here[^]
modified 21-Jul-12 15:31pm.
|
|
|
|
|
code and exact error mentioned in my first post..
Thanks in advance
|
|
|
|
|
jrahma wrote: code and exact error mentioned in my first post..
Then as you were already told the type that you are using IN THAT CODE, is wrong because it is a varchar. A varchar is not binary.
|
|
|
|
|
the VARCHAR was for the document format which is text representing the file extension.
The document itself is the param_resume_data...
|
|
|
|
|
Stating it again....
The type must be binary.
The code must reflect that.
The code in your first post does NOT reflect that.
The request was made that you post your code that has been UPDATED to use binary.
|
|
|
|
|
..and this happens for "all" files, without exception? Tried a very small picture?
If that's possible, consider the below modification;
file_stream.Write(document_binary, 0, document_binary.LongLength);
Bastard Programmer from Hell
if you can't read my code, try converting it here[^]
|
|
|
|
|
same problem with small pic. it's all coming to 1 byte file.
i tried changing it to your code like this:
file_stream.Write(document_binary, 0, document_binary.LongLength);
but getting this error:
The best overloaded method match for System.IO.Stream.Write(byte[], int, int) has some invalid arguments
Argument 3: cannot convert from 'long' to 'int'
|
|
|
|
|
jrahma wrote: i tried changing it to your code like this:
LongLength could be quite big; I suggest you write it in "chuncks" of int.MaxValue;
jrahma wrote: it's all coming to 1 byte file.
I hope that there's more than one byte in the database?
Bastard Programmer from Hell
if you can't read my code, try converting it here[^]
|
|
|
|
|
the field in the database is binary datatype with 255 length
|
|
|
|