Showing posts with label request. Show all posts
Showing posts with label request. Show all posts

Friday, March 23, 2012

How to get the error message rather than the code error

Hi,

After sending a request, I would get the possible error message.
Not the code @.@.error, nor the exact content of sysmessages, but the
message like it could be in the log file.

TIA,
TSalmTSalm (tsalm@.free.fr) writes:

Quote:

Originally Posted by

After sending a request, I would get the possible error message.
Not the code @.@.error, nor the exact content of sysmessages, but the
message like it could be in the log file.


"Sending a request", that sounds like you are issuing a call from a
client program. In that case you should be able to pick up the error
message. If you tell which client API you are using, I may even be
able to tell you how.

If you mean in a stored procedure, it depends on which version of SQL
Server you are on. If you are on SQL 2000, the answer is: you can't.

If you are on SQL 2005, you can use the new function error_message()
and its sisters: error_severity(), error_number(), error_state(),
error_procedure() and error_line(). But they only return data, if you
are in a CATCH handler, or a procedure called from a catch handler:

BEGIN TRY
-- Do something bad here
END TRY
BEGIN CATCH
SELECT error_message()
END CATCH

--
Erland Sommarskog, SQL Server MVP, esquel@.sommarskog.se
Books Online for SQL Server 2005 at
http://www.microsoft.com/technet/pr...oads/books.mspx
Books Online for SQL Server 2000 at
http://www.microsoft.com/sql/prodin...ions/books.mspx

How to get the Data in Values?

hi

i have creat some code to get data from Database like:

Dim strNewsIDAsInteger = Request.QueryString("ID")

Dim NewsconnAsNew System.Data.SqlClient.SqlConnection(ConfigurationManager.ConnectionStrings("SiteSQLServer").ToString())

Dim NewscmdAsNew System.Data.SqlClient.SqlCommand("SELECT FROM News (NewsGroupID, NewsTitle, News, NewsPosition) WHERE NewsID=strNewsID", Newsconn)

Now i wanna get Data in Values

Newsconn.Open()

Dim NewsGroupIDAsInteger = ???

Dim NewsTitleAsString = ???

Dim NewsAsString = ???

Dim NewsPositionAsInteger = ???

Please let me know how?

Newsconn.Close()

DrZ3D:

Dim NewscmdAsNew System.Data.SqlClient.SqlCommand("SELECT FROM News (NewsGroupID, NewsTitle, News, NewsPosition) WHERE NewsID=strNewsID", Newsconn)

I'm not a VB programmer, so someone else will have to help you with the VB syntax.

But the sql command is in a format I've never seen before.

I think you should be issuing this select statement:

"SELECTNewsGroupID, NewsTitle, News, NewsPositionFROM News WHERE ...

|||

you have an SQL connection and a querry.

So what you need now is a SQL Reader and then just loop throght this record set that is returned to get the values.

SqlDataReader readerAs new SqlCommand(query, conn)reader.ExecuteReader() if (reader.HasRows){// get the values here }
but are you getting 1 row returned or more?
|||

my conection is work and i get only one rowe from database

i only wana know how put the record in a value

thanks

|||

I'm not sure how will you provide the value forstrNewsID, so I'm leaving the problem on you. Other than that your modified code is below:

Dim strNewsIDAs Integer = Request.QueryString("ID")
Dim NewsconnAs New System.Data.SqlClient.SqlConnection(ConfigurationManager.ConnectionStrings("SiteSQLServer").ToString())

Dim NewscmdAs New System.Data.SqlClient.SqlCommand("SELECT NewsGroupID, NewsTitle, News, NewsPosition FROM News WHERE NewsID=strNewsID", Newsconn)

dim sdr as SqlDataReader

Dim NewsGroupIDAs Integer

Dim NewsTitleAs String

Dim NewsAs String

Dim NewsPositionAs Integer

Newsconn.Open()

sdr = Newscmd.executeReader()

if sdr.HasRows then

sdr.read()

NewsGroupID = sdr("NewsGroupID")
NewsTitle = sdr("NewsTitle")
News = sdr("News")
NewsPosition = sdr("NewsPosition")

end if

sdr.close()
newscommand.dispose()
Newsconn.Close()

Hope you will correct any syntactical errors.

Hope this will help.

Wednesday, March 21, 2012

how to get tables involved in constraint

Hi,
The following request select a constraint from TABLE_CONSTRAINT with
the name specified in the where clause:

select * from INFORMATION_SCHEMA.TABLE_CONSTRAINTS where
constraint_name = 'FK__51OtherParties__51Claims'

It returns:

http://graphicsxp.free.fr/constraint.JPG

So I have TABLE_NAME that correspond to the first table involved in the
constraint, but how do I get 51Claims ??

Thank youHi, Sam

You can use something like this:

SELECT TC.TABLE_NAME
FROM INFORMATION_SCHEMA.TABLE_CONSTRAINTS TC
INNER JOIN INFORMATION_SCHEMA.REFERENTIAL_CONSTRAINTS RC
ON TC.CONSTRAINT_NAME=RC.UNIQUE_CONSTRAINT_NAME
AND TC.CONSTRAINT_SCHEMA=RC.UNIQUE_CONSTRAINT_SCHEMA
WHERE RC.CONSTRAINT_NAME = 'FK__51OtherParties__51Claims'

Razvan|||Hi Razvan,

Many thanks, it works !