Hi André
Yes, this is way better. Because now you are doing less (you don't
allocate a new client command, you don't ask your server to parse your
statement 50.000 times, you don't ask your server to dispose his handle
50.000 times). But still you should dispose what you don't need. It always
surprises me that people think that dotnet is different from any other tool.
There are no such thing as "threads for noobs" or intelligent garbage
collection. .Net is monitoring you and can help you, but the old rules
still apply! (All of them)
Your code should actually be
//the using statement will clean up your command when it should be
cleaned up
Using (Dbcmd = Dbconn.CreateCommand()){
Dbcmd.Transaction = Dbtrans;
//Dbcmd.Connection = Dbconn; not needed, see above
//Dbcmd.CommandType = CommandType.Text; not needed, it is the
defaule
Dbcmd.CommandText = "INSERT INTO TEST(IDCODIGO,TESTE) VALUES
(@IDCodigo, @Teste)";
Dbcmd.Parameters.Add("@IDCodigo", FbDbType.VarChar, 6);
Dbcmd.Parameters.Add("@Teste", FbDbType.VarChar, 6);
for (int i = 0; i < 500000; i++){
Dbcmd.Parameters[0].Value = i.ToString();
Dbcmd.Parameters[1].Value = i.ToString();
Dbcmd.ExecuteNonQuery();
}
}
--------------------------------------------------
From: "André Knappstein, Controlling" <[email protected]>
Sent: Thursday, December 10, 2009 12:23 PM
To: "For users and developers of the Firebird .NET providers"
<[email protected]>
Subject: Re: [Firebird-net-provider] [FB-Tracker] Created: (DNET-287)
MemoryProblem when not dispose the DbCommand
> I don't know if the following method really is better, but it's worth
> a try, because from old school I would rather not create and destroy
> too many objects unnecessarily.
>
>
> Dbcmd = Dbconn.CreateCommand();
> Dbcmd.Transaction = Dbtrans;
> Dbcmd.Connection = Dbconn;
> Dbcmd.CommandType = CommandType.Text;
> Dbcmd.CommandText = "INSERT INTO TEST(IDCODIGO,TESTE) VALUES
> (@IDCodigo, @Teste)";
> Dbcmd.Parameters.Add("@IDCodigo", FbDbType.VarChar, 6);
> Dbcmd.Parameters.Add("@Teste", FbDbType.VarChar, 6);
>
> for (int i = 0; i < 500000; i++)
> {
> Dbcmd.Parameters[0].Value = i.ToString();
> Dbcmd.Parameters[1].Value = i.ToString();
> Dbcmd.ExecuteNonQuery();
> }
>
> ciao,
> André
>
>
> ------------------------------------------------------------------------------
> Return on Information:
> Google Enterprise Search pays you back
> Get the facts.
> http://p.sf.net/sfu/google-dev2dev
> _______________________________________________
> Firebird-net-provider mailing list
> [email protected]
> https://lists.sourceforge.net/lists/listinfo/firebird-net-provider
>
------------------------------------------------------------------------------
Return on Information:
Google Enterprise Search pays you back
Get the facts.
http://p.sf.net/sfu/google-dev2dev
_______________________________________________
Firebird-net-provider mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/firebird-net-provider