Tuesday, March 27, 2012
altering temporary tables
i have a simple stored procedure that takes input an integer..then inside it
it creates a temporary table & adds columns which are equal in number to the
integer that was inputed.
but iam encountering variuos error when i execute this procedure
here is the code(a very simple & small stored procedure):
create procedure mySolution @.colCount int as
declare @.i int
declare @.currTable varchar(10)
declare @.query nvarchar(255)
set @.i = 0
while @.i <= @.colCount
begin
set @.i = @.i + 1
if (@.i % 15 = 1)
begin
set @.query = 'create table #tasksecf'+cast((@.i/15) as nvarchar(255))+'
(empid int)'
set @.currTable = '#taskecf'+cast((@.i/15) as NVARCHAR(255))
exec(@.query)
end
set @.query = 'alter table '+@.currTable+' add col'+ cast(@.i as varchar)+ '
nvarchar(255)'
exec(@.query)
end
here are the errors :
if i execute this line
exec mySolution '15'
Server: Msg 4902, Level 16, State 1, Line 1
Cannot alter table '#taskecf0' because this table does not exist in database
'MyPracticeDB'.
Server: Msg 4902, Level 16, State 1, Line 1
Cannot alter table '#taskecf0' because this table does not exist in database
'MyPracticeDB'.
Server: Msg 4902, Level 16, State 1, Line 1
Cannot alter table '#taskecf0' because this table does not exist in database
'MyPracticeDB'.
Server: Msg 4902, Level 16, State 1, Line 1
Cannot alter table '#taskecf0' because this table does not exist in database
'MyPracticeDB'.
Server: Msg 4902, Level 16, State 1, Line 1
Cannot alter table '#taskecf0' because this table does not exist in database
'MyPracticeDB'.
Server: Msg 4902, Level 16, State 1, Line 1
Cannot alter table '#taskecf0' because this table does not exist in database
'MyPracticeDB'.
Server: Msg 4902, Level 16, State 1, Line 1
Cannot alter table '#taskecf0' because this table does not exist in database
'MyPracticeDB'.
Server: Msg 4902, Level 16, State 1, Line 1
Cannot alter table '#taskecf0' because this table does not exist in database
'MyPracticeDB'.
Server: Msg 4902, Level 16, State 1, Line 1
Cannot alter table '#taskecf0' because this table does not exist in database
'MyPracticeDB'.
Server: Msg 4902, Level 16, State 1, Line 1
Cannot alter table '#taskecf0' because this table does not exist in database
'MyPracticeDB'.
Server: Msg 4902, Level 16, State 1, Line 1
Cannot alter table '#taskecf0' because this table does not exist in database
'MyPracticeDB'.
Server: Msg 4902, Level 16, State 1, Line 1
Cannot alter table '#taskecf0' because this table does not exist in database
'MyPracticeDB'.
Server: Msg 4902, Level 16, State 1, Line 1
Cannot alter table '#taskecf0' because this table does not exist in database
'MyPracticeDB'.
Server: Msg 4902, Level 16, State 1, Line 1
Cannot alter table '#taskecf0' because this table does not exist in database
'MyPracticeDB'.
Server: Msg 4902, Level 16, State 1, Line 1
Cannot alter table '#taskecf0' because this table does not exist in database
'MyPracticeDB'.
Server: Msg 4902, Level 16, State 1, Line 1
Cannot alter table '#taskecf1' because this table does not exist in database
'MyPracticeDB'.Perhaps you should tell us what are you actually trying to achieve.
Each EXEC statement runs in a different context in which the local temporary
table created in the main procedure does not exist. Using a global table
would work, but I would advise against that - it may lead to other issues.
ML
http://milambda.blogspot.com/|||Hmmm, I think that temp table doesnt exists outside of the execution od
dynamic string and that would cause errors you get.
What are you trying to do with this sp? Perhaps you could explain the
requirement so we can try to find alternative solutions?
MC
"kishore bondada" <kishore bondada@.discussions.microsoft.com> wrote in
message news:361D5746-7137-4361-8BD0-D77150AF7326@.microsoft.com...
> hi all,
> i have a simple stored procedure that takes input an integer..then inside
> it
> it creates a temporary table & adds columns which are equal in number to
> the
> integer that was inputed.
> but iam encountering variuos error when i execute this procedure
> here is the code(a very simple & small stored procedure):
> create procedure mySolution @.colCount int as
> declare @.i int
> declare @.currTable varchar(10)
> declare @.query nvarchar(255)
> set @.i = 0
> while @.i <= @.colCount
> begin
> set @.i = @.i + 1
> if (@.i % 15 = 1)
> begin
> set @.query = 'create table #tasksecf'+cast((@.i/15) as nvarchar(255))+'
> (empid int)'
> set @.currTable = '#taskecf'+cast((@.i/15) as NVARCHAR(255))
> exec(@.query)
> end
> set @.query = 'alter table '+@.currTable+' add col'+ cast(@.i as varchar)+ '
> nvarchar(255)'
> exec(@.query)
> end
>
> here are the errors :
> if i execute this line
> exec mySolution '15'
> Server: Msg 4902, Level 16, State 1, Line 1
> Cannot alter table '#taskecf0' because this table does not exist in
> database
> 'MyPracticeDB'.
> Server: Msg 4902, Level 16, State 1, Line 1
> Cannot alter table '#taskecf0' because this table does not exist in
> database
> 'MyPracticeDB'.
> Server: Msg 4902, Level 16, State 1, Line 1
> Cannot alter table '#taskecf0' because this table does not exist in
> database
> 'MyPracticeDB'.
> Server: Msg 4902, Level 16, State 1, Line 1
> Cannot alter table '#taskecf0' because this table does not exist in
> database
> 'MyPracticeDB'.
> Server: Msg 4902, Level 16, State 1, Line 1
> Cannot alter table '#taskecf0' because this table does not exist in
> database
> 'MyPracticeDB'.
> Server: Msg 4902, Level 16, State 1, Line 1
> Cannot alter table '#taskecf0' because this table does not exist in
> database
> 'MyPracticeDB'.
> Server: Msg 4902, Level 16, State 1, Line 1
> Cannot alter table '#taskecf0' because this table does not exist in
> database
> 'MyPracticeDB'.
> Server: Msg 4902, Level 16, State 1, Line 1
> Cannot alter table '#taskecf0' because this table does not exist in
> database
> 'MyPracticeDB'.
> Server: Msg 4902, Level 16, State 1, Line 1
> Cannot alter table '#taskecf0' because this table does not exist in
> database
> 'MyPracticeDB'.
> Server: Msg 4902, Level 16, State 1, Line 1
> Cannot alter table '#taskecf0' because this table does not exist in
> database
> 'MyPracticeDB'.
> Server: Msg 4902, Level 16, State 1, Line 1
> Cannot alter table '#taskecf0' because this table does not exist in
> database
> 'MyPracticeDB'.
> Server: Msg 4902, Level 16, State 1, Line 1
> Cannot alter table '#taskecf0' because this table does not exist in
> database
> 'MyPracticeDB'.
> Server: Msg 4902, Level 16, State 1, Line 1
> Cannot alter table '#taskecf0' because this table does not exist in
> database
> 'MyPracticeDB'.
> Server: Msg 4902, Level 16, State 1, Line 1
> Cannot alter table '#taskecf0' because this table does not exist in
> database
> 'MyPracticeDB'.
> Server: Msg 4902, Level 16, State 1, Line 1
> Cannot alter table '#taskecf0' because this table does not exist in
> database
> 'MyPracticeDB'.
> Server: Msg 4902, Level 16, State 1, Line 1
> Cannot alter table '#taskecf1' because this table does not exist in
> database
> 'MyPracticeDB'.
>|||I've never tries t his, but perhaps you can switch your context to
tempdb and alter from there...once you find it.|||No, the problem is pre-compile, e.g. the parser can't find #table because
#table hasn't been created yet.
An alternative is to complete the whole chunk in dynamic SQL. Here is one
approach thatuses a permanent table tied to the SPID, this way you don't
have to do everything inside a single EXEC() (but you will still have to use
dynamic SQL to reference the table name):
DECLARE @.colCount INT;
SET @.colCount = 5;
DECLARE @.i INT,
@.TableName VARCHAR(32),
@.Query NVARCHAR(4000);
SET @.TableName = 'TaskSecF_'+RTRIM(@.@.SPID);
SET @.Query = 'IF OBJECT_ID('''+@.TableName+''') IS NOT NULL
DROP TABLE '+@.TableName+';
SELECT col1 = CONVERT(NVARCHAR(255), N'''')';
SET @.i = 1;
WHILE @.i <= @.colCount
BEGIN
SET @.i = @.i + 1
SET @.query = @.query + ',col'+RTRIM(@.i)+' = CONVERT(NVARCHAR(255), N'''')'
END
SET @.query = @.query + ' INTO '+@.TableName+' WHERE 1=2;'
EXEC(@.query)
EXEC('SELECT * FROM '+@.TableName);
...
EXEC('DROP TABLE '+@.TableName);
"MJKulangara" <RutgersDBA@.gmail.com> wrote in message
news:1139324385.781046.242250@.g43g2000cwa.googlegroups.com...
> I've never tries t his, but perhaps you can switch your context to
> tempdb and alter from there...once you find it.
>|||hi all,
first of all thank you all for your valuable replies. As asked by you iam
explaining the requirement a bit more clearly here:
Iam supposed to write a stored Procedure that takes input, an integer ' N '
and inside it create some temp tables, where each temp table contains ' X '
number of columns with datatype NVARCHAR(255).
since the SQL Server 2000 MAXROWSIZE limit is 8060 bytes, each temp table
can atmaximum contain 15 to 16 fields only (with datatype NVARCHAR(255)).
now if the user gives an input as integer 37, then
these temp tables should be created
#taskecf1 with fields col1 .... col15
#taskecf2 with fields col16 .... col30
#taskecf3 with fields col31 .... col37
and iam supposed to create temp tables only (not ordinary tables, i should
follow this coz, told by my project guide), after i complete this task, this
stored procedure is given to another student who will add his code to do
inserts & updates on these temp tables. hope this provides enough explanatio
n.
so i request you all to help me with this .
here is the code :
create procedure mySolution @.colCount int as
declare @.i int
declare @.currTable varchar(10)
declare @.query nvarchar(255)
set @.i = 0
while @.i <= @.colCount
begin
set @.i = @.i + 1
if (@.i % 15 = 1)
begin
set @.query = 'create table #tasksecf'+cast((@.i/15) as nvarchar(255))+'
(empid int)'
set @.currTable = '#taskecf'+cast((@.i/15) as NVARCHAR(255))
exec(@.query)
end
set @.query = 'alter table '+@.currTable+' add col'+ cast(@.i as varchar)+ '
nvarchar(255)'
exec(@.query)
end
if i execute this
exec mySolution '15'
here are the errors :
Server: Msg 4902, Level 16, State 1, Line 1
Cannot alter table '#taskecf0' because this table does not exist in database
'MyPracticeDB'.
Server: Msg 4902, Level 16, State 1, Line 1
Cannot alter table '#taskecf0' because this table does not exist in database
'MyPracticeDB'.
Server: Msg 4902, Level 16, State 1, Line 1
Cannot alter table '#taskecf0' because this table does not exist in database
'MyPracticeDB'.
Server: Msg 4902, Level 16, State 1, Line 1
Cannot alter table '#taskecf0' because this table does not exist in database
'MyPracticeDB'.
Server: Msg 4902, Level 16, State 1, Line 1
Cannot alter table '#taskecf0' because this table does not exist in database
'MyPracticeDB'.
Server: Msg 4902, Level 16, State 1, Line 1
Cannot alter table '#taskecf0' because this table does not exist in database
'MyPracticeDB'.
Server: Msg 4902, Level 16, State 1, Line 1
Cannot alter table '#taskecf0' because this table does not exist in database
'MyPracticeDB'.
Server: Msg 4902, Level 16, State 1, Line 1
Cannot alter table '#taskecf0' because this table does not exist in database
'MyPracticeDB'.
Server: Msg 4902, Level 16, State 1, Line 1
Cannot alter table '#taskecf0' because this table does not exist in database
'MyPracticeDB'.
Server: Msg 4902, Level 16, State 1, Line 1
Cannot alter table '#taskecf0' because this table does not exist in database
'MyPracticeDB'.
Server: Msg 4902, Level 16, State 1, Line 1
Cannot alter table '#taskecf0' because this table does not exist in database
'MyPracticeDB'.
Server: Msg 4902, Level 16, State 1, Line 1
Cannot alter table '#taskecf0' because this table does not exist in database
'MyPracticeDB'.
Server: Msg 4902, Level 16, State 1, Line 1
Cannot alter table '#taskecf0' because this table does not exist in database
'MyPracticeDB'.
Server: Msg 4902, Level 16, State 1, Line 1
Cannot alter table '#taskecf0' because this table does not exist in database
'MyPracticeDB'.
Server: Msg 4902, Level 16, State 1, Line 1
Cannot alter table '#taskecf0' because this table does not exist in database
'MyPracticeDB'.
Server: Msg 4902, Level 16, State 1, Line 1
Cannot alter table '#taskecf1' because this table does not exist in database
'MyPracticeDB'|||i got the work done with the help of global temporary tables.
but some of you commented that it would lead to some other issues...can u
please elaborate what they are?
"ML" wrote:
> Perhaps you should tell us what are you actually trying to achieve.
> Each EXEC statement runs in a different context in which the local tempora
ry
> table created in the main procedure does not exist. Using a global table
> would work, but I would advise against that - it may lead to other issues.
>
> ML
> --
> http://milambda.blogspot.com/|||Well, its global. That means that all processes 'see' and affect those
tables. If there are two calls of your procedure at the same time, you'll be
in trouble.
MC
"kishore bondada" <kishorebondada@.discussions.microsoft.com> wrote in
message news:89E8BD16-C428-4C77-9BBB-CC2D4CDEC055@.microsoft.com...
>i got the work done with the help of global temporary tables.
> but some of you commented that it would lead to some other issues...can u
> please elaborate what they are?
> "ML" wrote:
>|||Try executing your script in two separate sessions step-by-step - i.e. creat
e
the object in the first session, then in the second, make the changes in the
first, then in the second, etc.
After each step check the state of the object (perhaps from a third
connection). You'll see what I mean.
Even this situation can be remedied by giving the objects unique names (e.g.
including SPID in the table name), but this only leads to more dynamic SQL.
Is this the purpose of this exercise?
In real-life situations the requirements for a data model are known in
advance and allow for more efficient planning. But that's another story. :)
ML
http://milambda.blogspot.com/|||i thank u all for ur valuable suggestions..
i solved the uniqueness issue of global temporary tables by using your idea
of including the @.@.SPID as part of the table name when creating the
tables...please inform me of any other issues involved
regards,
kishore
"ML" wrote:
> Try executing your script in two separate sessions step-by-step - i.e. cre
ate
> the object in the first session, then in the second, make the changes in t
he
> first, then in the second, etc.
> After each step check the state of the object (perhaps from a third
> connection). You'll see what I mean.
> Even this situation can be remedied by giving the objects unique names (e.
g.
> including SPID in the table name), but this only leads to more dynamic SQL
.
> Is this the purpose of this exercise?
> In real-life situations the requirements for a data model are known in
> advance and allow for more efficient planning. But that's another story. :
)
>
> ML
> --
> http://milambda.blogspot.com/
Monday, February 13, 2012
ALL 'try/catch/finally' NOT created equal?
catch does not handle it... (I know this code is wrong, I want to
force the error for this example)
try
{
DataSet ds = new DataSet();
string strID = ds.Tables[0].Rows[0][0].ToString();
}
catch (SqlXmlException sqlxmlerr)
{
sqlxmlerr.ErrorStream.Position = 0;
StreamReader errreader = new StreamReader(sqlxmlerr.ErrorStream);
string err =errreader.ReadToEnd();
errreader.Close();
throw new Exception (err);
}
finally
{
}
This is a ASP.NET application and when the code hits 'string strID =
ds.Tables[0].Rows[0][0].ToString();' the exception is throw and the
result below is displayed in the browser.
*************
Cannot find table 0.
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.IndexOutOfRangeException: Cannot find table
0.
Source Error:
Line 29: {
Line 30: DataSet ds = new DataSet();
Line 31: strID = ds.Tables[0].Rows[0][0].ToString();
Line 32: }
Line 33: catch (SqlXmlException sqlxmlerr)
*************
Now, if I replace SqlXmlException with System.Exception in the
catch(), the try/catch handles they way I thought and no browser error
happens, the code goes directly to my catch (during debugging, I made
sure)....
So my question.
Just because I have a try/catch doesn't mean it will ALWAYS catch
an exception. I guess I have proven this but wanted confirmation. So
how do I know what exception class to use? Where can I find this
information.
Thanks
Ralph Krausse
www.consiliumsoft.com
Use the START button? Then you need CSFastRunII...
A new kind of application launcher integrated in the taskbar!
ScreenShot - http://www.consiliumsoft.com/ScreenShot.jpg
You might want to post in one of the .NET NGs rather than the SQL Server XML
one. However...
The exception in your example is not a SqlException - the error is caused by
a call to a managed class (the DataSet class), so it's a System.Exception.
SqlExceptions are thrown when the server raises an exception (so for example
when an error occurs in a stored procedure you have called).
To be safe, you should generally structure your exception handling this way:
try
{
// your code
}
catch (SqlExecption se)
{
// handle SqlException
}
catch (Exception ex)
{
// handle System.Exception
}
finally
{
//clean up code
}
The idea is to create a catch clase for each exception that's likely to
occur, ordering them from more specific to more generic.
Hope that helps,
Graeme
--
Graeme Malcolm
Principal Technologist
Content Master Ltd.
www.contentmaster.com
"Ralph Krausse" <gordingin@.consiliumsoft.com> wrote in message
news:49eb6317.0408200638.7209f631@.posting.google.c om...
I created a try/catch/finally but when an expection is thrown, the
catch does not handle it... (I know this code is wrong, I want to
force the error for this example)
try
{
DataSet ds = new DataSet();
string strID = ds.Tables[0].Rows[0][0].ToString();
}
catch (SqlXmlException sqlxmlerr)
{
sqlxmlerr.ErrorStream.Position = 0;
StreamReader errreader = new StreamReader(sqlxmlerr.ErrorStream);
string err =errreader.ReadToEnd();
errreader.Close();
throw new Exception (err);
}
finally
{
}
This is a ASP.NET application and when the code hits 'string strID =
ds.Tables[0].Rows[0][0].ToString();' the exception is throw and the
result below is displayed in the browser.
*************
Cannot find table 0.
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.IndexOutOfRangeException: Cannot find table
0.
Source Error:
Line 29: {
Line 30: DataSet ds = new DataSet();
Line 31: strID = ds.Tables[0].Rows[0][0].ToString();
Line 32: }
Line 33: catch (SqlXmlException sqlxmlerr)
*************
Now, if I replace SqlXmlException with System.Exception in the
catch(), the try/catch handles they way I thought and no browser error
happens, the code goes directly to my catch (during debugging, I made
sure)....
So my question.
Just because I have a try/catch doesn't mean it will ALWAYS catch
an exception. I guess I have proven this but wanted confirmation. So
how do I know what exception class to use? Where can I find this
information.
Thanks
Ralph Krausse
www.consiliumsoft.com
Use the START button? Then you need CSFastRunII...
A new kind of application launcher integrated in the taskbar!
ScreenShot - http://www.consiliumsoft.com/ScreenShot.jpg
|||Just to add one tiny point of clarification to Graeme's explanation - the
catch block is only executed if the type of exception specified as the
parameter of the catch clause matches the type of exception that is thrown
by the code in the try block. If you specify System.Exception as the
parameter to the catch block it will catch all exceptions since every
exception in the .Net framework inherits from System.Exception.
In general, catching System.Exception can be dangerous in your code because
it means you may be catching a security exception or a stress condition like
OutOfMemoryException. I agree with Graeme that you want to catch the most
specific exception first and get more general as you go down the catch
blocks but be very careful when catching System.Exception. For more
information on best practices for exception handling check out
http://msdn.microsoft.com/library/de...guidelines.asp
Thanks,
Adam Wiener [MSFT]
This posting is provided "AS IS" with no warranties, and confers no rights.
"Graeme Malcolm" <graemem_cm@.hotmail.com> wrote in message
news:O8Ndf$shEHA.4064@.TK2MSFTNGP12.phx.gbl...
> You might want to post in one of the .NET NGs rather than the SQL Server
XML
> one. However...
> The exception in your example is not a SqlException - the error is caused
by
> a call to a managed class (the DataSet class), so it's a System.Exception.
> SqlExceptions are thrown when the server raises an exception (so for
example
> when an error occurs in a stored procedure you have called).
> To be safe, you should generally structure your exception handling this
way:
> try
> {
> // your code
> }
> catch (SqlExecption se)
> {
> // handle SqlException
> }
> catch (Exception ex)
> {
> // handle System.Exception
> }
> finally
> {
> //clean up code
> }
> The idea is to create a catch clase for each exception that's likely to
> occur, ordering them from more specific to more generic.
> Hope that helps,
> Graeme
> --
> --
> Graeme Malcolm
> Principal Technologist
> Content Master Ltd.
> www.contentmaster.com
>
> "Ralph Krausse" <gordingin@.consiliumsoft.com> wrote in message
> news:49eb6317.0408200638.7209f631@.posting.google.c om...
> I created a try/catch/finally but when an expection is thrown, the
> catch does not handle it... (I know this code is wrong, I want to
> force the error for this example)
>
> try
> {
> DataSet ds = new DataSet();
> string strID = ds.Tables[0].Rows[0][0].ToString();
> }
> catch (SqlXmlException sqlxmlerr)
> {
> sqlxmlerr.ErrorStream.Position = 0;
> StreamReader errreader = new StreamReader(sqlxmlerr.ErrorStream);
> string err =errreader.ReadToEnd();
> errreader.Close();
> throw new Exception (err);
> }
> finally
> {
> }
> This is a ASP.NET application and when the code hits 'string strID =
> ds.Tables[0].Rows[0][0].ToString();' the exception is throw and the
> result below is displayed in the browser.
> *************
> Cannot find table 0.
> 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.IndexOutOfRangeException: Cannot find table
> 0.
> Source Error:
>
> Line 29: {
> Line 30: DataSet ds = new DataSet();
> Line 31: strID = ds.Tables[0].Rows[0][0].ToString();
> Line 32: }
> Line 33: catch (SqlXmlException sqlxmlerr)
> *************
>
> Now, if I replace SqlXmlException with System.Exception in the
> catch(), the try/catch handles they way I thought and no browser error
> happens, the code goes directly to my catch (during debugging, I made
> sure)....
> So my question.
>
> Just because I have a try/catch doesn't mean it will ALWAYS catch
> an exception. I guess I have proven this but wanted confirmation. So
> how do I know what exception class to use? Where can I find this
> information.
> Thanks
> Ralph Krausse
> www.consiliumsoft.com
> Use the START button? Then you need CSFastRunII...
> A new kind of application launcher integrated in the taskbar!
> ScreenShot - http://www.consiliumsoft.com/ScreenShot.jpg
>
|||
> I created a try/catch/finally but when an expection is thrown, the
> catch does not handle it... (I know this code is wrong, I want to
> force the error for this example)
>
> try
> {
> DataSet ds = new DataSet();
> string strID = ds.Tables[0].Rows[0][0].ToString();
> }
> catch (SqlXmlException sqlxmlerr)
> {
> sqlxmlerr.ErrorStream.Position = 0;
> StreamReader errreader = new StreamReader(sqlxmlerr.ErrorStream);
> string err =errreader.ReadToEnd();
> errreader.Close();
> throw new Exception (err);
> }
> finally
> {
> }
> This is a ASP.NET application and when the code hits 'string strID =
> ds.Tables[0].Rows[0][0].ToString();' the exception is throw and the
> result below is displayed in the browser.
> *************
> Cannot find table 0.
> 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.IndexOutOfRangeException: Cannot find table
> 0.
> Source Error:
>
> Line 29: {
> Line 30: DataSet ds = new DataSet();
> Line 31: strID = ds.Tables[0].Rows[0][0].ToString();
> Line 32: }
> Line 33: catch (SqlXmlException sqlxmlerr)
> *************
>
> Now, if I replace SqlXmlException with System.Exception in the
> catch(), the try/catch handles they way I thought and no browser error
> happens, the code goes directly to my catch (during debugging, I made
> sure)....
> So my question.
>
> Just because I have a try/catch doesn't mean it will ALWAYS catch
> an exception. I guess I have proven this but wanted confirmation. So
> how do I know what exception class to use? Where can I find this
> information.
> Thanks
> Ralph Krausse
> www.consiliumsoft.com
> Use the START button? Then you need CSFastRunII...
> A new kind of application launcher integrated in the taskbar!
> ScreenShot - http://www.consiliumsoft.com/ScreenShot.jpg
User submitted from AEWNET (http://www.aewnet.com/)
|||Well, your code is doing exactly what it says.
You coded:
catch (SqlXmlException sqlxmlerr)
which MEANS catch errors of this type [SqlXmlException] here.
The error thrown was for [System.IndexOutOfRangeException].
To catch ALL errors in on place use something like
catch(Exception e)
you can nest you catch clauses like
catch (SqlXmlException sqlxmlerr) {}
catch(Exception e){}
finianly{}
see BOL and the language specification for more details.
dlr
"Guest" <Guest@.aew_nospam.com> wrote in message
news:%23ZYEUnpSFHA.1160@.tk2msftngp13.phx.gbl...
>
> User submitted from AEWNET (http://www.aewnet.com/)
ALL 'try/catch/finally' NOT created equal?
> I created a try/catch/finally but when an expection is thrown, the
> catch does not handle it... (I know this code is wrong, I want to
> force the error for this example)
>
> try
> {
> DataSet ds = new DataSet();
> string strID = ds.Tables[0].Rows[0][0].ToString();
> }
> catch (SqlXmlException sqlxmlerr)
> {
> sqlxmlerr.ErrorStream.Position = 0;
> StreamReader errreader = new StreamReader(sqlxmlerr.ErrorStream);
> string err =errreader.ReadToEnd();
> errreader.Close();
> throw new Exception (err);
> }
> finally
> {
> }
> This is a ASP.NET application and when the code hits 'string strID =
> ds.Tables[0].Rows[0][0].ToString();' the exception is throw and the
> result below is displayed in the browser.
> *************
> Cannot find table 0.
> 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.IndexOutOfRangeException: Cannot find table
> 0.
> Source Error:
>
> Line 29: {
> Line 30: DataSet ds = new DataSet();
> Line 31: strID = ds.Tables[0].Rows[0][0].ToString();
> Line 32: }
> Line 33: catch (SqlXmlException sqlxmlerr)
> *************
>
> Now, if I replace SqlXmlException with System.Exception in the
> catch(), the try/catch handles they way I thought and no browser error
> happens, the code goes directly to my catch (during debugging, I made
> sure)....
> So my question.
>
> Just because I have a try/catch doesn't mean it will ALWAYS catch
> an exception. I guess I have proven this but wanted confirmation. So
> how do I know what exception class to use? Where can I find this
> information.
> Thanks
> Ralph Krausse
> www.consiliumsoft.com
> Use the START button? Then you need CSFastRunII...
> A new kind of application launcher integrated in the taskbar!
> ScreenShot - http://www.consiliumsoft.com/ScreenShot.jpg
User submitted from AEWNET (http://www.aewnet.com/)Well, your code is doing exactly what it says.
You coded:
catch (SqlXmlException sqlxmlerr)
which MEANS catch errors of this type [SqlXmlException] here.
The error thrown was for [System.IndexOutOfRangeException].
To catch ALL errors in on place use something like
catch(Exception e)
you can nest you catch clauses like
catch (SqlXmlException sqlxmlerr) {}
catch(Exception e){}
finianly{}
see BOL and the language specification for more details.
dlr
"Guest" <Guest@.aew_nospam.com> wrote in message
news:%23ZYEUnpSFHA.1160@.tk2msftngp13.phx.gbl...
>
> User submitted from AEWNET (http://www.aewnet.com/)
Thursday, February 9, 2012
All Hardware Being Equal
Does SQL Server 2005 Express perform equal to SQL Server 2005 Enterprise? Basically, if the hardware that both editions were deployed on was identical and configured with in conjunction with the hardware limitations that Express imposes, would the two editions perform the same when running the same querries?
I have read that SQL Express uses the same database engine but does this mean that the Express edition will perform as well as the Enterprise edition?
SQL Express has certain limits. Only 1 CPU is used, only 1GB of RAM is used, no 64-bit support, databases can't be larger than 4GB. If you're comparing SQL Express to SQL Enterprise on a hardware above these things, Enterprise will definitely be faster as it doesn't have such limits.
From a software standpoint, the only performance feature difference I'm aware of is that SQL Enterprise will consider Indexed Views when optimizing queries... any lesser version (inlcuding SQL Standard) will not do this.
There may be differences in the default configuration of the editions, too.
So, as you can see, it's a bit tricky to get an apples-to-apples comparison :-) All things considered, though, the performance should be pretty close on small databases.
-Ryan / Kardax