|
I have one stored procedure, and it having UPDATE and INSERT statements, The INSERT / UPDATE queries are inside a Begin transaction, if the transaction fails then rollback the transaction otherwise commit it.
If the error occur rollback the transaction as well as i want to catch the exception and throwuh it to the user in the DA Class
I am calling the stored peocedure in the DA Class
please tell me any suggestions
Awaiting for reply
thanks
-
|
|
|
|
|
IF @@ERROR <> 0
ROLLBACK
RAISEERROR...
ELSE
COMMIT
|
|
|
|
|
Or don't have the transaction in teh sproc, but handle it through the DA class:
SqlTransaction tran = new SqlTransaction(conn);
try
{
... call sproc
tran.Commit();
}
catch (SqlException sqlEx)
{
tran.Rollback();
}
|
|
|
|
|
Be careful with this approach. Some Transactions may still get automatically rolled back, which will cause the rollback statement in the code to throw another exception.
Typically, SQL server rolls back transactions when a severe error or a connection loss occurs. This can be handled by issuing the rollback transaction in a nested try catch, and handling the error if the transaction was already rolled back.
We need to graduate from the ridiculous notion that greed is some kind of elixir for capitalism - it's the downfall of capitalism. Self-interest, maybe, but self-interest run amok does not serve anyone. The core value of conscious capitalism is enlightened self-interest.
Patricia Aburdene
|
|
|
|
|
how can i return 0 (false) for an error to insert data in SQL database. i am using ASP.Net (using vb.net) to call the stored procedure....
my procedure is...
CREATE PROCEDURE Insert_Book (
@arg_Title VARCHAR(255),
@arg_Price VARCHAR,
@arg_PublishDate DATETIME,
@arg_BookID INT OUT)
AS
DECLARE @rc Int
BEGIN
INSERT INTO
Book (
Title,
Price,
PublishDate )
VALUES (
@arg_Title,
@arg_Price,
@arg_PublishDate );
/*SELECT @arg_BookID = @@IDENTITY;*/
IF @@ERROR <> 0
BEGIN
/*SELECT @rc = 0*/
/*Print convert(Varchar,"An error occurred while adding the new Book information")*/
RETURN (99)
END
ELSE
BEGIN
/*SELECT @rc =99*/
/*PRINT Convert(Varchar,"The new author information has been loaded")*/
RETURN (0)
END
procedure call is...
con = New clarion.connection
Conn = New SqlClient.SqlConnection
Conn.ConnectionString = con.GetConnectionString()
Dim cmdtxt As SqlClient.SqlParameter
Dim objErr As SqlClient.SqlException
Dim txtAbbreviation As String
Dim txtReturnCode As String
Conn.Open()
Dim cmd As New SqlClient.SqlCommand("Insert_Book", Conn)
cmd.CommandType = CommandType.StoredProcedure
cmdtxt = cmd.Parameters.Add("@arg_Title", "Nisha")
cmdtxt.Direction = ParameterDirection.Input
cmdtxt = cmd.Parameters.Add("@arg_Price", "")
cmdtxt.Direction = ParameterDirection.Input
cmdtxt = cmd.Parameters.Add("@arg_PublishDate", "01/05/06")
cmdtxt.Direction = ParameterDirection.Input
cmdtxt = cmd.Parameters.Add("@arg_BookID", "")
cmdtxt.Direction = ParameterDirection.Input
cmdtxt = cmd.Parameters.Add("@@Error", SqlDbType.Int)
cmdtxt.Direction = ParameterDirection.ReturnValue
cmd.ExecuteNonQuery()
Conn.Close()
If Convert.ToInt32(cmd.Parameters.Item("@@error").Value) <> 0 Then
txtAbbreviation = Convert.ToString(cmd.Parameters.Item("RC").Value)
txtReturnCode = Convert.ToString(cmd.Parameters.Item("@@error").Value)
Else
txtAbbreviation = Convert.ToString(cmd.Parameters.Item("@arg_Price").Value)
txtReturnCode = Convert.ToString(cmd.Parameters.Item("@@error").Value)
End If
Dinesh Sharma
Software Engineer
|
|
|
|
|
look up ExecuteScaler
object retValue = [SqlCommand].ExecuteScalar() ;
|
|
|
|
|
How do I access Query Designer from Microsoft SQL Server Management Studio? I mean the equivalent in SQL Server Enterprise Manager of
Table -> Open Table -> Query
I just can't find the equivalent from the menus.
Also how to access DTS?
Probably all very obvious!
Thanks
Majella
|
|
|
|
|
Just open a table and then click on one of the toolbar buttons on the lower toolbar that appears. You have diagram, sql and criteria buttons.
Kevin
|
|
|
|
|
I have this script here. But I need to redo it as a sub Query can someone help me?
SELECT
fp.flt_numb,
a.name as 'destination airport',
a.cty_iata_code,
b.name as 'possible landing airport'
FROM flight_profiles fp
JOIN airports a
ON a.iata_code = fp.to
JOIN airports b
ON a.cty_iata_code = b.cty_iata_code
ORDER BY fp.flt_numb;
|
|
|
|
|
|
I need to re-write this as a sub query:
Select
f.FLT_NUMB as 'Flight Number',
b.Name as 'Arrive Airpots',
a.Name as 'Airports'
from airports a
join flight_profiles f
join airports b
on a.cty_iata_code = f.to and b.iata_code = f.to
group by a.Name
order by f.flt_numb
|
|
|
|
|
I got re-wrote like this
select
d.flight_no,
d.destination,
a.Name as "Alternative Airort"
from airports a,
((SELECT b.FLIGHT_NUMBER FLIGHT_NO,
b.DESTINATION DESTINATION,
a1.cty_IATA_CODE AS CTY_CODE,
a1.name as airport_names
FROM AIRPORTS a1,
((SELECT FLT_NUMB FLIGhT_NUMBER,
F.TO DESTINATION FROM FLIGHT_PROFILES F) AS b)
WHERE b.DESTINATION=a1.IATA_CODE)as D)
where a.cty_iata_code=d.cty_code
order by d.flight_no
and its work fine.
|
|
|
|
|
Hi,
well i think i'm so stupide to ask that but i really tried ma besqt with it & it doesn't work
i created a stored procedure in this procedure i have 1 parameter type datetime
& i want to select * from a table where day(this table.dat_start)/month(dat_start)/year(the parameter) = the parameter
i will make it more clear
supposing parameter is '02/05/2006'
(select * from season where day(dat_start)/month(dat_start)/year('02/05/2006') = '02/05/2006')
it dosen't want to of course because the two types are defferent but i did a convert & it dosen't ant too
(select * from season where convert(datetime,day(dat_start)/month(dat_start)/year('02/05/2006')) = '02/05/2006')
& i did a cast & no result
(select * from season where cast(day(dat_start)/month(dat_start)/year('02/05/2006')as datetime) = '02/05/2006')
well i talked a lot i think i hope you understand please if you have the solution can you help, me ?
thank you very much
try to be good if you can't be the best
|
|
|
|
|
create Proc p_date (@dateS varchar(111))
as
Begin
select * from season where Convert(varchar,dat_start,111)=@dateS
end
if u have problem with this proc just mail me
moinul@apollodhaka.com
Moinul
Sr.Executive IT
Apollo Hospitals Dhaka
|
|
|
|
|
I need to run my program on my client machine.
I had developed my program on my machine and created the DB on my machine.
Now I need to transfer the db and my EXE file on to another machine
The server name on my machine shows
Running - \\Rch1 - MSSQLServer
But the server name on the second machine
Running - \\Krnot - MSSQLServer
How do I replace the servername.
My code;
Public conn As New OleDbConnection("Provider=sqloledb;server=Rch1;Database=Rch;Trusted_Connection=YES;")
Tnx
|
|
|
|
|
You should always put that kind of information in the app.cofig file. That way it can be changed when the application is moved around. Hardcoding this information into the app is just going to cause problems (as you have seen)
"On two occasions, I have been asked [by members of Parliament], 'Pray, Mr. Babbage, if you put into the machine wrong figures, will the right answers come out?' I am not able to rightly apprehend the kind of confusion of ideas that could provoke such a question."
--Charles Babbage (1791-1871)
My: Website | Blog
|
|
|
|
|
Pls Could you give me some more info on this.
Tnx
|
|
|
|
|
|
What is the best way of distributing an empty (of transactional data) database in MS_SQL2k?
I have a database which has gone through system test and want to use this as the UAT baseline database - maybe do a backup and restore as a new database..or use tha database copy wizard?
Any other options?
'--8<------------------------
Ex Datis:
Duncan Jones
Merrion Computing Ltd
|
|
|
|
|
Duncan Edwards Jones wrote: I have a database which has gone through system test and want to use this as the UAT baseline database - maybe do a backup and restore as a new database..or use tha database copy wizard?
I have some NUnit tests that restore a database in the TestFixtureSetUp method. It works very well - although sometimes it can be a little slow, so I have a set of delete scripts in reserve if I'm debugging though the unit tests and I need a quick reset between runs.
"On two occasions, I have been asked [by members of Parliament], 'Pray, Mr. Babbage, if you put into the machine wrong figures, will the right answers come out?' I am not able to rightly apprehend the kind of confusion of ideas that could provoke such a question."
--Charles Babbage (1791-1871)
My: Website | Blog
-- modified at 9:01 Monday 15th May, 2006
|
|
|
|
|
You can use SQL Server Enterprise Manager to Generate Scripts of your entire database.
Right Click db -> All Tasks -> Generate SQL Script...
Look where you want to go not where you don't want to crash.
Bikers Bible
|
|
|
|
|
Hi,
I have one employ table, i want to find the nth max salary
can anybody know how to write a query please send to me
|
|
|
|
|
Something like this might work:
SELECT TOP 1 EmployeeID, Salary
FROM
(
SELECT TOP n EmployeeID, Salary
FROM EmployeeTable
ORDER BY Salary DESC
) AS TopSalaries
ORDER BY Salary ASC Remember to replace the n in TOP n with the actual literal value that you need (unless you are using SQL Server 2005)
"On two occasions, I have been asked [by members of Parliament], 'Pray, Mr. Babbage, if you put into the machine wrong figures, will the right answers come out?' I am not able to rightly apprehend the kind of confusion of ideas that could provoke such a question."
--Charles Babbage (1791-1871)
My: Website | Blog
|
|
|
|
|
If you don't mind temp tables this should work
######
DECLARE @TopSalary int
SET @TopSalary = 10 -- Get me the 10th hightest paid employee
create table #temp(id int Indentity(1,1) employeeID int, salary float)
insert #temp
insert employee, salary from YourTable
ORDER BY SALARY DESC
SELECT * from temp
WHERE ID = 10
Look where you want to go not where you don't want to crash.
Bikers Bible
|
|
|
|
|