Store Procedures

Answer

Well-known member
Joined
Jul 2, 2002
Messages
46
Location
USA
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!
 
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
C#:
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.
 
Back
Top