?
Solved

problem with the using statement.

Posted on 2008-06-23
7
Medium Priority
?
1,982 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
CHALLENGE LAB: Troubleshooting Connectivity Issues

Goal: Fix the connectivity issue in the lab's AWS environment so that you can SSH into the provided EC2 instance.  

 
LVL 2

Accepted Solution

by:
Alexey_Varlamov earned 2000 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

Veeam Task Manager for Hyper-V

Task Manager for Hyper-V provides critical information that allows you to monitor Hyper-V performance by displaying real-time views of CPU and memory at the individual VM-level, so you can quickly identify which VMs are using host resources.

Question has a verified solution.

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

This article shows how to deploy dynamic backgrounds to computers depending on the aspect ratio of display
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
This tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…
Suggested Courses

801 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