Difference between Clone, Close and Dispose methods of Crystal Report?
Close() Vs Dispose Method
The basic difference between Close() and Dispose() is, when a Close() method is called, any managed resource can be temporarily closed and can be opened once again. It means that, with the same object the resource can be reopened or used. Where as Dispose() method permanently removes any resource ((un)managed) from memory for cleanup and the resource no longer exists for any further processing.
Example showing difference between Close() and Dispose() Method:
using System;
using System.Data;
using System.Data.SqlClient;
public class Test
{
private string connString = “Data Source=COMP3;Initial Catalog=Northwind;User Id=sa;Password=pass”;
private SqlConnection connection;
public Test()
{
connection = new SqlConnection(connString);
}
private static void Main()
{
Test t = new Test();
t.ConnectionStatus();
Console.ReadLine();
}
public void ConnectionStatus()
{
try
{
if(connection.State == ConnectionState.Closed)
{
connection.Open();
Console.WriteLine(“Connection opened..”);
}
if(connection.State == ConnectionState.Open)
{
connection.Close();
Console.WriteLine(“Connection closed..”);
}
// connection.Dispose();
if(connection.State == ConnectionState.Closed)
{
connection.Open();
Console.WriteLine(“Connection again opened..”);
}
}
catch(SqlException ex)
{
Console.WriteLine(ex.Message+”\n”+ex.StackTrace);
}
catch(Exception ey)
{
Console.WriteLine(ey.Message+”\n”+ey.StackTrace);
}
finally
{
Console.WriteLine(“Connection closed and disposed..”);
connection.Dispose();
}
}
}
In the above example if you uncomment the “connection.Dispose()” method and execute, you will get an exception as, “The ConnectionString property has not been initialized.”.This is the difference between Close() and Dispose().
Using Dataset.clone() creates new instance of the same object.
Using Dataset.copy() copies content of data to another object wihtout creating new instance.
Clone : Copy only structure
Copy : Copy Structure & Data Both
Popularity: unranked [?]
Related interview questions
- On the create tablespace, what does the CLOSE parameter do?
- What are the different methods of accessing db2 from tso?B.How is the connection established between TSO & DB2?
- How can I create a Singleton class by using public constructor?
- What happens when you open an empty VSAM file in a COBOL program for input?
- DB2 : SQL Codes and Description



(4 votes, average: 4.75 out of 5)







Leave your response!
You must be logged in to post a comment.