Write CLOBs to files
The example in this topic connects to the superstores_demo database and writes all of the CLOBs in the table catalog into files in the directory C:\tmp. The same technique is used to write BLOBs to files.
Note that the IfxClob instance must be opened before it is accessed.
For more information about the IfxClob class see IfxClob class.
try
{
// Open a connection
IfxConnection conn =
new IfxConnection(
"Host=myhost;" +
"Service=1576;" +
"Server=mydbserver;"+
"Database=superstores_demo;" +
"User ID=mylogin;password=mypassword"
);
conn.Open();
// Create an SQL command
IfxCommand cmd = new IfxCommand(
"SELECT advert_descr, catalog_num FROM catalog",
conn
);
IfxDataReader dr = cmd.ExecuteReader();
// Write any CLOBs to files in C:\tmp
while (dr.Read())
{
if(!dr.IsDBNull(0)){
IfxClob c = dr.GetIfxClob(0);
long num = dr.GetInt64(1);
c.Open(Informix.Net.Core.IfxSmartLOBOpenMode.ReadOnly);
c.ToFile(
"C:\\tmp\\" + num.ToString() + ".txt",
System.IO.FileMode.Create,
IfxSmartLOBFileLocation.Client
);
}
}
dr.Close();
// Close the connection
conn.Close();
}
catch(Exception e)
{
//This is assumed to be a console application
Console.WriteLine(e.ToString());
}