Re: Timeout in .NET but not in Management Studio by me
me
Thu Feb 21 11:05:15 CST 2008
On Feb 11, 3:10=A0am, nok <n...@discussions.microsoft.com> wrote:
> Hello,
> Here is some more background on my problem
>
> Connection strings, for local machine and remote
>
> <connectionStrings>
> <add name=3D"dbDsn" providerName=3D"System.Data.SqlClient"
> connectionString=3D"server=3DOVEKERWXPP2\SQL2005;database=3Ddl2;uid=3Dd_dl=
ek_u1;pwd=3Dxxxx;"/>
> <!--add name=3D"dbDsn" providerName=3D"System.Data.SqlClient"
> connectionString=3D"server=3Ds-ekdb1.int.lio.se;database=3Ddlpe;uid=3Dd_dl=
ekonomi_u1;pwd=3Dyyy;"/-->
> =A0 </connectionStrings>
>
> =A0 (I have used the approach SqlDataReader =3D SqlCommand..ExecuteReader(=
);
> =A0 with the same result too)
> =A0 The time is spent in adapter.Fill().
> =A0 A) I invoke the code using the SQL Server local to my development mach=
ine.
> =A0 It executes in 3 secs returning 4000 rows.
> =A0 B) I invoke the code using the remote SQL Server.
> =A0 The query takes more than 30 sec for 400 rows..
> =A0 C) I invoke the Stored Procedure from SQL 2005 Mangement Studio. The Q=
uery
> executes in 3 secs on both the local
> =A0 and the remote server.
>
> =A0 The query texts =A0look identical in SQL Server Profiler. As I mention=
ed
> they yield different Scan patterns.
> =A0 My first thought was that I missed something in the input parameter ty=
ping
> so that eg a string would be interpeted as
> =A0 as an int causing tedious conversions and scans.
>
> =A0 exec GetRRSelOrgShowKonto
> @inPe=3D'207',@inOrgFrom=3D'00000',@inOrgTom=3D'99999',@inDatumfrom=3D'200=
801',@inDatumtom=3D'200806',@inExtInt=3D'a',@inBudget=3D'a'
>
> =A0 =A0 This is my code simplified
>
> =A0 =A0 =A0 =A0 SqlConnection conn;
> =A0 =A0 =A0 =A0 SqlCommand cmd =3D null;
> =A0 =A0 =A0 =A0 DataTableReader dr;
>
> =A0 =A0 =A0 =A0 conn =3D new SqlConnection(DbConnectionString);
> =A0 =A0 =A0 =A0 try
> =A0 =A0 =A0 =A0 {
> =A0 =A0 =A0 =A0 =A0 =A0 conn.Open();
> =A0 =A0 =A0 =A0 =A0 =A0 cmd =3D new SqlCommand("GetRRSelOrgShowKonto", con=
n);
> =A0 =A0 =A0 =A0 =A0 =A0 cmd.CommandType =3D CommandType.StoredProcedure;
> =A0 =A0 =A0 =A0 =A0 =A0 cmd.CommandTimeout =3D 90;
> =A0 =A0 =A0 =A0 =A0 =A0 cmd.Parameters.Add(new SqlParameter("@inPe", SqlDb=
Type.Char,3));
> =A0 =A0 =A0 =A0 =A0 =A0 cmd.Parameters["@inPe"].Value =3D InPe;
> =A0 =A0 =A0 =A0 =A0 =A0 cmd.Parameters.Add(new SqlParameter("@inOrgFrom",
> SqlDbType.Char, 5));
> =A0 =A0 =A0 =A0 =A0 =A0 cmd.Parameters["@inOrgFrom"].Value =3D InOrgFrom;
> =A0 =A0 =A0 =A0 =A0 =A0 cmd.Parameters.Add(new SqlParameter("@inOrgTom", S=
qlDbType.Char,
> 5));
> =A0 =A0 =A0 =A0 =A0 =A0 cmd.Parameters["@inOrgTom"].Value =3D InOrgTom;
> =A0 =A0 =A0 =A0 =A0 =A0 cmd.Parameters.Add(new SqlParameter("@inDatumfrom"=
,
> SqlDbType.Char, 6));
> =A0 =A0 =A0 =A0 =A0 =A0 cmd.Parameters["@inDatumfrom"].Value =3D InBokdatF=
rom;
> =A0 =A0 =A0 =A0 =A0 =A0 cmd.Parameters.Add(new SqlParameter("@inDatumtom",=
> SqlDbType.Char, 6));
> =A0 =A0 =A0 =A0 =A0 =A0 cmd.Parameters["@inDatumtom"].Value =3D InBokdatTo=
m;
> =A0 =A0 =A0 =A0 =A0 =A0 cmd.Parameters.Add(new SqlParameter("@inExtInt", S=
qlDbType.Char,
> 1));
> =A0 =A0 =A0 =A0 =A0 =A0 cmd.Parameters["@inExtInt"].Value =3D InExtInt;
> =A0 =A0 =A0 =A0 =A0 =A0 cmd.Parameters.Add(new SqlParameter("@inBudget", S=
qlDbType.Char,
> 1));
> =A0 =A0 =A0 =A0 =A0 =A0 cmd.Parameters["@inBudget"].Value =3D InBudget;
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 Response.Write("Starting "=
+ DateTime.Now.ToString());
> =A0 =A0 =A0 =A0 =A0 =A0 DataSet data =3D new DataSet();
> =A0 =A0 =A0 =A0 =A0 =A0 SqlDataAdapter adapter =3D new SqlDataAdapter(cmd)=
;
> =A0 =A0 =A0 =A0 =A0 =A0 adapter.Fill(data);
> =A0 =A0 =A0 =A0 =A0 =A0 Response.Write("Finished Fill" + DateTime.Now.ToSt=
ring());
> =A0 =A0 =A0 =A0 =A0 =A0 dr =3D data.CreateDataReader();
> =A0 =A0 =A0 =A0 =A0 =A0 Response.Write("Finished CreateDataReader" +
> DateTime.Now.ToString());
> =A0 =A0 =A0 =A0 =A0 =A0 while (dr.Read())
> =A0 =A0 =A0 =A0 =A0 =A0 {
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 // Use the data ... (String)dr["ko=
nto"] etc.
> =A0 =A0 =A0 =A0 =A0 =A0 }
> =A0 =A0 =A0 =A0 }
> =A0 =A0 =A0 =A0 catch (Exception ex)
> =A0 =A0 =A0 =A0 {
> =A0 =A0 =A0 =A0 =A0 // Ends up in a .NET timeout here if i decrease the Ti=
meOut setting
> =A0 =A0 =A0 =A0 }
> =A0 =A0 =A0 =A0 finally
> =A0 =A0 =A0 =A0 {
> =A0 =A0 =A0 =A0 =A0 =A0 conn.Close();
> =A0 =A0 =A0 =A0 }
Not sure if it is your problem or not, but I was having this same
exact behaviour: same stored procedure, different execute times
from .NET and Management Studio. Using Profiler I was able to narrow
it down to the ARITHABORT setting. It is OFF by default from .NET and
ON from Management Studio. When the setting was ON the execution time
was 1 second and when it was OFF the execution time was 47 seconds.
Not sure how, but it seemed to have something to do with my use of
table variables in the stored procedure. Once I changed the stored
procedure to use a temp table instead, the execution time was the same
regardless of the ARITHABORT setting.