Solved

problem with the using statement.

Posted on 2008-06-23
7
1,976 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
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!

 
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

Wouldn’t it be nice if you could test whether an element is contained in an array by using a Contains method just like the one available on List objects? Wouldn’t it be good if you could write code like this? (CODE) In .NET 3.5, this is possible…
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
This is a high-level webinar that covers the history of enterprise open source database use. It addresses both the advantages companies see in using open source database technologies, as well as the fears and reservations they might have. In this…
NetCrunch network monitor is a highly extensive platform for network monitoring and alert generation. In this video you'll see a live demo of NetCrunch with most notable features explained in a walk-through manner. You'll also get to know the philos…

728 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