Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

Sorry for the newb questions, but i am just learing MSDE and SQL and i must says its pretty impressive. But i do have a few questions.

 

#1, should i use store procedures to do my inserts, updates and deletes as opposed to using hte command object and executing a nonquery?

 

 

#2, I am writing classes that represent the databases. Should open the connection object for each class for the entire duration of the classes life just once. Or should i open and close it for every function that requires having a connection, such as sending a insert command.

 

 

Thanks for your help in advanced!

Posted

L

 

Remeber one thing while working with SQL

 

1- For Insert / Update , always use Store procedures coz SQL uses very powerful memory management so using stored procedurs will speed up your entries rather then writing Insert or Update Statements. and its a secure method you dont need to put the table name in the CommandObject just the procedure name and Parameters.

This is better to use Stored Procedures.

 

2. for SQL Connection, Rememeber a rule of thumb.

 

try to open the connection as late as possible , and after your query close it as soon as possible.

 

its better to use this mecehnism

try
   {
         cnSQL.Open
         SQLCOMMEND.EXECUTENONQUERY
         cnSQL.Close
    }

Catch ( Excetion ex )

    {
        MessageBox.Show(ex.ToString());
    }
Finally
     {
           if (cnSQL.State == ConnectionState.Open)
             {
                     cnSQL.Close();

             }

     }

 

This method is very good because if it founds the connection open it will close it.

The one and only

Dr. Madz

eee-m@il

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...