SqlCommand not returning an error!

  • Thread starter Thread starter tascien
  • Start date Start date
T

tascien

Hi, when i use this code:

SqlConn.Open()
SqlCmd.Connection = SqlConn
SqlCmd.CommandText = sqlCommand
If Not CmdTimeOut < 0 Then SqlCmd.CommandTimeout =
CmdTimeOut
Dim ret = SqlCmd.ExecuteNonQuery()
SqlConn.Close()
Return ret

and pass the SQL Query:

ALTER VIEW [dbo].[tb_Custom_Join_1] AS SELECT [tb_Contact].[LastName]
AS [tb_Contact_LastName],[tb_Contact].(e-mail address removed)
 
Tascien,

It is almost for sure not a bug in ADONET.

Try to get some information how to use ADONET.

Your code will almost for sure open by instance a connection on a by you not
wanted server and close it after a while and has done nothing.

Known good writers of ADONET books are David Sceppa and Bill Vaughn.

You can as well try this website.

http://samples.gotdotnet.com/quickstart/

Sorry it does not helps a lot, however your message shows a lot of unknown
basics.

Cor
 
There are two places things can go wrong. One is you get an exception
in your ADO.NET code, which you can handle in your try/catch block.
Two is you get some kind of data error from SQL Server. This does not
necessarily throw an exception in ADO.NET, depending on the severity
level of the error. SQL BOL discusses this in the topics "Using
@@ERROR" and "Handling Errors and Messages in Applications". The most
efficient and robust way to deal with SQL Server errors is to create
stored procedures that handle complex processes, processing data
errors there. You then return success/failure information to your
client application using either output parameters, a return statement,
or a result set.

--Mary
 
Ok,

so you say it's my code. No problem. What code would you suggest. I
will use it and see if it throws an exception!

I don't think the problem lies in the code. I think the problem might
lie in ADO.NET, because when i use ADO

Set conn = CreateObject("ADODB.Connection")
conn.Open Connectionstring
conn.Execute SQLQUERY
conn.close

it does throw an exception.

Note, Only the above query is the one that is not throwing an exception
in dotnet. Other malformed query do throw exception using the same
code...

Tascien
 
Tascien,

Sorry I was reading your commandtext as connection text and was confused
that it was set after the open.

If Not CmdTimeOut < 0 Then SqlCmd.CommandTimeout = CmdTimeOut

Why did you insert that.

Although I am not known with the communication between all kind of SQL
server commands that should create errors.

In my opinion is the main purpose of the executenonquerry to use with
transactions for datatables and not for views. However I can be wrong in
that.

Cor


However I never tried it, can you see what the
 
In my opinion is the main purpose of the executenonquerry to use with
transactions for datatables and not for views. However I can be wrong in
that.

That might make sense. What i am trying to do, is alter a view. May be
ExecuteNonQuery does not work with CREATING and ALTERING views. I built
an interface where the users will be creating and modifying views, and
if there is an error, the user should see it.

All i know that, it is classing ADO's connection object Execute method
works. And ADO.NET's ExecuteNonQuery does not work. No worry though. I
have found a way to include classing ADO in my dotnet project. Where
ADO.NET does not work, ADO will...

Tascien
 
Back
Top