Solved

problem with the using statement.

Posted on 2008-06-23
7
1,966 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
Comment Utility
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
Comment Utility
/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
Comment Utility
u confused me.
0
IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 
LVL 2

Accepted Solution

by:
Alexey_Varlamov earned 500 total points
Comment Utility
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
Comment Utility
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
Comment Utility
       [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
Comment Utility
it still fails on me don;t i have to add th cursor.
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Introduction Hi all and welcome to my first article on Experts Exchange. A while ago, someone asked me if i could do some tutorials on object oriented programming. I decided to do them on C#. Now you may ask me, why's that? Well, one of the re…
Today I had a very interesting conundrum that had to get solved quickly. Needless to say, it wasn't resolved quickly because when we needed it we were very rushed, but as soon as the conference call was over and I took a step back I saw the correct …
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…

772 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now