Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Use Ent LIb to deserialize a SqlParameter

Status
Not open for further replies.

KCWMS

MIS
Mar 25, 2004
38
US
using the June 2005 edition of the Ent Lib.

I can serialize a SqlParameterCollection using
ConfigurationManager.WriteConfiguration() but GetConfiguration() does not seem to be able to deserialize that same ParameterCollection. The TestConfiguration.config file looks perfect... I actually said "Cool!" when I first saw it!

A small sample app follows.

**Note**
If I uncomment the three line in Main, the GetConfiguration() works fine... but then my reading indicates that at that point GetConfiguration is actually reading cached data, which is pointless.

Am I not corrrect in understanding that the config block should behave like the old *.ini files: a plain text and human readable config file that can be read at runtime?

How can I accomplish this?

In the example below, mytest2 is created with the _myName variable as "Billy"
but the _pcol variable as undefined.

****code example************

using System;
using System.Data.SqlClient;
using System.Data;
using Microsoft.Practices.EnterpriseLibrary.Configuration;

namespace AccountUserMigration
{
public class Test{
private SqlParameterCollection _pcol;
private string _myName;

public string myName{
get{return this._myName;}
set{this._myName = value;}
}

public SqlParameterCollection pcol{
get{return this._pcol;}
set{this._pcol = value;}
}

public Test(){}

public void PrepForSerialization(){
SqlCommand cmd = new SqlCommand();
cmd.Parameters.Add("@one",SqlDbType.VarChar);
cmd.Parameters.Add("@two",SqlDbType.Int);
this.pcol = cmd.Parameters;
this.myName = "Billy";
}

static void Main(){
//Test mytest = new Test(), mytest2 = new Test();
//mytest.PrepForSerialization();
//ConfigurationManager.WriteConfiguration("TestConfiguration",mytest);

Test mytest2 =
(Test)ConfigurationManager.GetConfiguration("TestConfiguration") as Test;
}
}
}

**************************
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top