Solved

problem with the using statement.

Posted on 2008-06-23
7
1,968 Views
Last Modified: 2013-12-16
Error      2      'Microsoft.Practices.EnterpriseLibrary.Data.Database': type used in a using statement must be implicitly convertible to 'System.IDisposable'      C:\SvnWork\InitialPriceReporting\DotNet\InitialPriceReportingService\App_Code\InitialPriceReportingService.cs      749      12      C:\...\InitialPriceReportingService\

 [WebMethod(Description = "Compare PriceList")]
        public DataSet ComparePriceListDelete(string OldPriceList, string NewPriceList, ref string Status)
        {
           
           string procedureName = "init_price.PRICE_LIST_REPORTING.price_list_deletions"; //schema.stored procedure

           System.Data.DataSet DSNew = new DataSet();
           using (Database db = DatabaseFactory.CreateDatabase("InitialPrices.Properties.Settings.ConnectionString"))
           {
                DbCommand dbCommand = db.GetStoredProcCommand(procedureName);
                db.AddInParameter(dbCommand, "p_old_price_list_id", DbType.String, OldPriceList);
                db.AddInParameter(dbCommand, "p_new_price_list_id", DbType.String, NewPriceList);
                db.AddOutParameter(dbCommand, "p_status", DbType.String, 255);


                DSNew = db.ExecuteDataSet(dbCommand);
            }

            // Reset the variables
            return (DSNew);
        }
0
Comment
Question by:mathieu_cupryk
  • 4
  • 3
7 Comments
 
LVL 2

Expert Comment

by:Alexey_Varlamov
ID: 21847014
Add the IDisposable interface inheritance to your class and impement the Dispose() method.
This method should cleanup all unmanaged resources or do nothing.
0
 
LVL 2

Expert Comment

by:Alexey_Varlamov
ID: 21847043
/ops, the Database class is not your class... do no use the "using" statement if this class does not implement the IDisposable interface  :))   - the reason described above.
0
 

Author Comment

by:mathieu_cupryk
ID: 21847050
u confused me.
0
Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

 
LVL 2

Accepted Solution

by:
Alexey_Varlamov earned 500 total points
ID: 21847147
Just use the
Database db = DatabaseFactory.CreateDatabase("InitialPrices.Properties.Settings.ConnectionString"))

without "using" statement. The using statement is equvalent to:

try
{
   Database db = DatabaseFactory.CreateDatabase("InitialPrices.Properties.Settings.ConnectionString"))
  .... <your code>
}
finally
{
   ((IDisposable)db).Dispose();'
}

So, the class should implement the IDisposable interface (that have only one method - Dispose()). The Database class does not implement the IDisposable interface, so there is no need to cleanup code.
0
 

Author Comment

by:mathieu_cupryk
ID: 21847396
Error      1      The name 'db' does not exist in the current context      C:\SvnWork\InitialPriceReporting\DotNet\InitialPriceReportingService\App_Code\InitialPriceReportingService.cs      772      29      C:\...\InitialPriceReportingService\
0
 
LVL 2

Expert Comment

by:Alexey_Varlamov
ID: 21847614
       [WebMethod(Description = "Compare PriceList")]
        public DataSet ComparePriceListDelete(string OldPriceList, string NewPriceList, ref string Status)
        {
           string procedureName = "init_price.PRICE_LIST_REPORTING.price_list_deletions"; //schema.stored procedure

           System.Data.DataSet DSNew = new DataSet();
           Database db = DatabaseFactory.CreateDatabase("InitialPrices.Properties.Settings.ConnectionString"))
            DbCommand dbCommand = db.GetStoredProcCommand(procedureName);
            db.AddInParameter(dbCommand, "p_old_price_list_id", DbType.String, OldPriceList);
            db.AddInParameter(dbCommand, "p_new_price_list_id", DbType.String, NewPriceList);
            db.AddOutParameter(dbCommand, "p_status", DbType.String, 255);
            DSNew = db.ExecuteDataSet(dbCommand);
            // Reset the variables
            return (DSNew);
        }
0
 

Author Comment

by:mathieu_cupryk
ID: 21848229
it still fails on me don;t i have to add th cursor.
0

Featured Post

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

More often than not, we developers are confronted with a need: a need to make some kind of magic happen via code. Whether it is for a client, for the boss, or for our own personal projects, the need must be satisfied. Most of the time, the Framework…
This article shows how to deploy dynamic backgrounds to computers depending on the aspect ratio of display
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

776 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question