Showing posts with label statements. Show all posts
Showing posts with label statements. Show all posts

Thursday, March 29, 2012

General Network Error Check network documentation

Hi I get a "General Network Error Check network documentation" error sometimes, but its only while insert or update statements are fired while selects keep working perfectly.

The Error details are as follows:

General network error. Check your network documentation.

Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.Data.SqlClient.SqlException: General network error. Check your network documentation.

Source Error:

An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.

Stack Trace:

[SqlException: General network error. Check your network documentation.]

System.Data.SqlClient.SqlCommand.ExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream)

If once a update is fired from IDE it takes long to respond but once its done the error disappears.

Any body any Idea.

Wednesday, March 21, 2012

further informations

Just for the record:
- the statements are viewed exactly before execution with an unicode aware
application and they contain the right unicodes.
- the db columns supposed to store the unicodes are defined as nvarchar
- the db viewer (SQL Query Analizer) is also unicode aware. It shows right
unicodes for values inserted with "preparedStatements" but ''?...' for
those inserted with plain statements.
?Hint?
In statements we don't use the N prefix for the unicode values. F.ex.:
we do:
UPDATE Table1 SET Col1 = 'New Text' WHERE id = 1
not:
UPDATE Table1 SET Col1 = N'New Text' WHERE id = 1
Is there a way to eliminate the necessity of using N by means of DB/SQL
Server settings?
Many thanks in advance.I think the '? show up because you insert non-unicode strings, and
there's a mismatch between the code pages of the process that changes the
data and the process that reads the data.
The ideal way to fix this would be to stop generating UPDATE statements, if
you can't change your code like that then you need to insert the values as
Unicode.
As a side note, you'll want to pay attention to injection attacks.
In the statement below:
UPDATE Table1 SET Col1 = N'New Text' WHERE id = 1
If the value of 'Nex Text' comes from the user then you need to escape it
with QUOTENAME
UPDATE Table1 SET Col1 = QUOTENAME(N'New Text','''') WHERE id = 1
Otherwise it can be injected with >>>>New Text' do_a_bad_thing_here --<<<<
UPDATE Table1 SET Col1 = N'New Text' do_a_bad_thing_here -- WHERE id = 1
Ciprian Gerea
SDE, SqlServer
This posting is provided "AS IS" with no warranties, and confers no rights.
"Cristian Senchiu" <Cristian Senchiu@.discussions.microsoft.com> wrote in
message news:88F7BF72-A378-4A4D-9D42-E2F9F98C697A@.microsoft.com...
> Just for the record:
> - the statements are viewed exactly before execution with an unicode aware
> application and they contain the right unicodes.
> - the db columns supposed to store the unicodes are defined as nvarchar
> - the db viewer (SQL Query Analizer) is also unicode aware. It shows right
> unicodes for values inserted with "preparedStatements" but ''?...' for
> those inserted with plain statements.
> ?Hint?
> In statements we don't use the N prefix for the unicode values. F.ex.:
> we do:
> UPDATE Table1 SET Col1 = 'New Text' WHERE id = 1
> not:
> UPDATE Table1 SET Col1 = N'New Text' WHERE id = 1
> Is there a way to eliminate the necessity of using N by means of DB/SQL
> Server settings?
> Many thanks in advance.

Monday, March 12, 2012

Function with CASE Statements

Hi,

Uses: SQL Server 2000 + Winxp PRO;

I Created a Function as below:

<CODE>
CREATE FUNCTION [GetDestinationOperator] (@.Dest VARCHAR(24))
RETURNS VARCHAR(15)
AS
BEGIN

DECLARE @.Op VARCHAR(15)

SET @.Dest = RTRIM(@.Dest)

CASE LEN(@.Dest)
WHEN 13 THEN SET @.Op = 'IDD'
WHEN 10 THEN
CASE SUBSTRING (@.Dest , 1 , 3 )
WHEN '071' THEN SET @.Op = 'MOBITEL'
WHEN '072' THEN SET @.Op = 'CELTEL'
WHEN '077' THEN SET @.Op = 'DIALOG'
WHEN '078' THEN SET @.Op = 'HUTCH'
ELSE SET @.Op = 'NATIONAL'
END
WHEN 7 THEN
CASE SUBSTRING (@.Dest , 1 , 1 )
WHEN '2' THEN SET @.Op = 'SLT'
WHEN '4' THEN SET @.Op = 'SUNTEL'
WHEN '5' THEN SET @.Op = 'LANKA BELL'
ELSE SET @.Op = 'LOCAL'
END
WHEN 3 THEN SET @.Op = 'INTERNAL'
ELSE SET @.Op = 'UNKNOWN'
END

RETRUN @.Op

END
<\CODE>

However when I checked the Code I written I get error Message as saying:

Error = 156:
Incorrect Syntax near the Keyword CASE
Incorrect Syntax near the Keyword WHEN
.
.
.

However when I executed the Query which I used with my database mentioned below, I get no errors:

<CODE>

SELECT CASE LEN(CalledNo)
WHEN 13 THEN 'IDD'
WHEN 10 THEN
CASE SUBSTRING (CalledNo , 1 , 3 )
WHEN '071' THEN 'MOBITEL'
WHEN '072' THEN 'CELTEL'
WHEN '077' THEN 'DIALOG'
WHEN '078' THEN 'HUTCH'
ELSE 'NATIONAL'
END
WHEN 7 THEN
CASE SUBSTRING (CalledNo , 1 , 1 )
WHEN '2' THEN 'SLT'
WHEN '4' THEN 'SUNTEL'
WHEN '5' THEN 'LANKA BELL'
ELSE 'LOCAL'
END
WHEN 3 THEN 'INTERNAL'
ELSE 'UNKNOWN'
END, CalledNo
FROM PABX
WHERE ExtNo = 204

<\CODE>

What might be the problem here?

Regards,

Hifni

Can you try this
CREATE FUNCTION GetDestinationOperator (@.Dest VARCHAR(24))
RETURNS VARCHAR(15)
AS
BEGIN

DECLARE @.Op VARCHAR(15)

SET @.Dest = RTRIM(@.Dest)
select @.op=
CASE LEN(@.Dest)
WHEN 13 THEN 'IDD'
WHEN 10 THEN
CASE SUBSTRING (@.Dest , 1 , 3 )
WHEN '071' THEN 'MOBITEL'
WHEN '072' THEN 'CELTEL'
WHEN '077' THEN 'DIALOG'
WHEN '078' THEN 'HUTCH'
ELSE 'NATIONAL'
END
WHEN 7 THEN
CASE SUBSTRING (@.Dest , 1 , 1 )
WHEN '2' THEN 'SLT'
WHEN '4' THEN 'SUNTEL'
WHEN '5' THEN 'LANKA BELL'
ELSE 'LOCAL'
END
WHEN 3 THEN 'INTERNAL'
ELSE 'UNKNOWN'
END

RETURN @.Op

END|||The case statement cannot stand alone even within a fuction. Create a variable called @.result and modify your fuction to Select @.result = <your case statement> then return the result.|||

Replace the CASE statment with a series of

IF condition

BEGIN

...

END

That should work

|||CASE is an expression not a control of flow statement. So you need to either assign the variable @.op using the value of the CASE expression or use IF...ELSE statements. Also, you should avoid writing scalar UDFs like this which perform lookup operations and use it in SELECT statements. You will get sub-optimal performance. It is based to model the lookup in a table and then perform a simple SELECT operation. This also gives added flexibility and performs better. Or you can inline the expression in the UDF in a view or TVF and use that instead.|||

Hi Everyone,
Thanks for all of your responses. For Eisa, I tried your sql and it did work wery well. Thanks for it and Umarchandra who gave a technical detail of it, thanks as well and for the rest.

Regards,