Solved

problem with the using statement.

Posted on 2008-06-23
7
1,974 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Salesforce Has Never Been Easier

Improve and reinforce salesforce training & adoption using WalkMe's digital adoption platform. Start saving on costly employee training by creating fast intuitive Walk-Thrus for Salesforce. Claim your Free Account Now

 
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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

This document covers how to connect to SQL Server and browse its contents.  It is meant for those new to Visual Studio and/or working with Microsoft SQL Server.  It is not a guide to building SQL Server database connections in your code.  This is mo…
Many of us here at EE write code. Many of us write exceptional code; just as many of us write exception-prone code. As we all should know, exceptions are a mechanism for handling errors which are typically out of our control. From database errors, t…
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an antispam), the admini…

737 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