Wrox Programmer Forums
Go Back   Wrox Programmer Forums > .NET > Other .NET > ADO.NET
|
ADO.NET For discussion about ADO.NET.  Topics such as question regarding the System.Data namespace are appropriate.  Questions specific to a particular application should be posted in a forum specific to the application .
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ADO.NET section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old July 12th, 2005, 09:30 PM
Authorized User
 
Join Date: Jun 2005
Posts: 97
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via Yahoo to aldwinenriquez
Default Timeout problem with SqlTransaction

I want to implement transaction within three database insert methods.

void Method1(parameters,connection,transaction)
{
cmd.Connection = connection;
cmd.Transaction = transaction;
...
}

void Method2(parameters,connection,transaction)
{
cmd.Connection = connection;
cmd.Transaction = transaction;
...
}
void Method3(parameters,connection,transaction)
{
cmd.Connection = connection;
cmd.Transaction = transaction;
...
}

Inside Main method I create the connection object and SqlTransaction object.

con.Open();
transaction = con.BeginTransaction();

Method1(con,transaction);//along with other parameters
Method2(con,transaction);
Method2(con,transaction);

After calling these methods I got these....

"Timeout
expired. The timeout period elapsed prior to completion
of the operation or the server is not responding."

Removing the transaction works OK but I want operations to be transacted..

Any ideas?

"Dont you ever give up!"
__________________
\"Dont you ever give up!\"
 
Old July 13th, 2005, 12:26 PM
Friend of Wrox
 
Join Date: Oct 2004
Posts: 224
Thanks: 0
Thanked 1 Time in 1 Post
Send a message via MSN to ashu_from_india Send a message via Yahoo to ashu_from_india
Default

hi

use same SQLCommand object for all the procedures.

Ashu


 
Old July 14th, 2005, 05:43 AM
Authorized User
 
Join Date: Jun 2005
Posts: 97
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via Yahoo to aldwinenriquez
Default

doesn't fix that..I still have problems.

I created a SqlCommand object and passed it to all the methods.Timeout problem is still thrown.......

"Dont you ever give up!"
 
Old July 14th, 2005, 09:12 AM
Friend of Wrox
 
Join Date: Oct 2004
Posts: 224
Thanks: 0
Thanked 1 Time in 1 Post
Send a message via MSN to ashu_from_india Send a message via Yahoo to ashu_from_india
Default

can u post or mail the source code ?

Ashu


 
Old July 18th, 2005, 01:49 AM
Authorized User
 
Join Date: Jun 2005
Posts: 97
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via Yahoo to aldwinenriquez
Default

Here's how it look like:

//Here is the main method
public void SubmitSection(string xml)
{
SqlConnection con = new SqlConnection(conStr);
SqlTransaction tran = null;
SqlCommand cmd = new SqlCommand();
try{
con.Open();
tran = con.BeginTransaction();
//XML processing codes here
//first call
InsertValues(tmpSqlString,section["Fields"],fieldsTable,cmd);
cmd.Parameters.Clear();
UpdateLastSectionSubmitted(m_sectionId,con);
cmd.Parameters.Clear();
UpdateEnrolmentStatus((uint)subjectId,1,cmd);
//commit transaction
tran.Commit();
}catch(Exception){
//rollback the transaction
tran.RollBack();
}finally{
    con.Close();
}



private void InsertValues(string sql,SqlCommand cmd)
{
StringBuilder mySqlString = new StringBuilder();
    SqlCommand cmd = new SqlCommand();
    //build the sql string
    mySqlString.Append(sql);
    cmd.CommandText = mySqlString.ToString();
    cmd.CommandType = CommandType.Text;
    try
    {
        cmd.ExecuteNonQuery();
    }catch(SqlException) {
         throw;
    }
}

//same thing happens in other two methods
//setting command parameters
//executing the command


"Dont you ever give up!"
 
Old July 18th, 2005, 12:29 PM
Friend of Wrox
 
Join Date: Oct 2004
Posts: 224
Thanks: 0
Thanked 1 Time in 1 Post
Send a message via MSN to ashu_from_india Send a message via Yahoo to ashu_from_india
Default

hi

Dont make a new SQLCommand object in the Insert procedure and pass the SQLCommand object ByRef.

Also initialize the Connection and Transaction properties for the SQLCommand object.

Ashu


 
Old July 18th, 2005, 09:15 PM
Authorized User
 
Join Date: Jun 2005
Posts: 97
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via Yahoo to aldwinenriquez
Default

i have initialize the cmd transaction and Connection parameters on the SubmitSection method,sorry i had removed it...il try passing the cmd object by reference. thanks

"Dont you ever give up!"





Similar Threads
Thread Thread Starter Forum Replies Last Post
Session timeout problem zaheerabbas.sk .NET Framework 1.x 3 April 10th, 2007 02:14 AM
Asp .Net 2.0 request/response timeout problem VijayT .NET Framework 2.0 5 February 5th, 2007 01:26 PM
ODBC Timeout Problem echovue Access VBA 3 February 2nd, 2007 08:27 AM
ASP.Net Timeout Problem busher ASP.NET 1.0 and 1.1 Professional 1 December 8th, 2005 01:17 AM
Form not submitting - Timeout problem? danlinn General .NET 1 June 24th, 2004 08:40 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.