I am using reflection to create a data access component. I have the
following code:

SqlConnection o_Temp = new SqlConnection();
System.Data.IDbConnection o_Connection;
o_Connection = o_Temp as IDbConnection;

This works correctly but it does not use reflection. Now I am looking to
use this code:


System.Reflection.Assembly o_Assembly =
System.Reflection.Assembly.LoadWithPartialName("System.Data");
object o_Temp2 =
o_Assembly.CreateInstance("System.Data.SqlClient.SqlConnection");
System.Data.IDbConnection o_Connection;
o_Connection = o_Temp2 as IDbConnection;

This does not work as o_Connection is null when it attempts to cast. Any
idea why this would be?

Thanks in advance!

Re: Reflection with SqlConnection by Kathleen

Kathleen
Fri Jul 11 12:09:55 CDT 2003

I copied your code and it works fine here. Look for another problem past the
line that is doing the cast.

Kathleen

"WebDevHokie" <mwitczak@rkeng.com> wrote in message
news:OaPPw7wRDHA.1556@TK2MSFTNGP10.phx.gbl...
> I am using reflection to create a data access component. I have the
> following code:
>
> SqlConnection o_Temp = new SqlConnection();
> System.Data.IDbConnection o_Connection;
> o_Connection = o_Temp as IDbConnection;
>
> This works correctly but it does not use reflection. Now I am looking to
> use this code:
>
>
> System.Reflection.Assembly o_Assembly =
> System.Reflection.Assembly.LoadWithPartialName("System.Data");
> object o_Temp2 =
> o_Assembly.CreateInstance("System.Data.SqlClient.SqlConnection");
> System.Data.IDbConnection o_Connection;
> o_Connection = o_Temp2 as IDbConnection;
>
> This does not work as o_Connection is null when it attempts to cast. Any
> idea why this would be?
>
> Thanks in advance!
>
>



Re: Reflection with SqlConnection by Kathleen

Kathleen
Mon Jul 14 09:40:16 CDT 2003

FWIW, this machine has both the frameworks on it.

But I don't think I can help you here. Before you burn a support call, maybe
repair the .NET your working in, if its on a single machine.

Kathleen


"WebDevHokie" <mwitczak@rkeng.com> wrote in message
news:OE9eHA#RDHA.1804@TK2MSFTNGP11.phx.gbl...
> Well I have found a deeper issue. This problem is only seen when the
> machine has both the 1.0 and the 1.1 frameworks on it. I have tested in
the
> 1.0 only environment and the 1.1 environment and both work properly. But
> when the machine has both frameworks on it, it fails. I have a feeling I
am
> going to have to contact Microsoft about this one!
>
> WebDevHokie
>
>
> "Kathleen Dollard" <kathleen@mvps.org> wrote in message
> news:OEI2988RDHA.212@TK2MSFTNGP10.phx.gbl...
> > I copied your code and it works fine here. Look for another problem past
> the
> > line that is doing the cast.
> >
> > Kathleen
> >
> > "WebDevHokie" <mwitczak@rkeng.com> wrote in message
> > news:OaPPw7wRDHA.1556@TK2MSFTNGP10.phx.gbl...
> > > I am using reflection to create a data access component. I have the
> > > following code:
> > >
> > > SqlConnection o_Temp = new SqlConnection();
> > > System.Data.IDbConnection o_Connection;
> > > o_Connection = o_Temp as IDbConnection;
> > >
> > > This works correctly but it does not use reflection. Now I am looking
> to
> > > use this code:
> > >
> > >
> > > System.Reflection.Assembly o_Assembly =
> > > System.Reflection.Assembly.LoadWithPartialName("System.Data");
> > > object o_Temp2 =
> > > o_Assembly.CreateInstance("System.Data.SqlClient.SqlConnection");
> > > System.Data.IDbConnection o_Connection;
> > > o_Connection = o_Temp2 as IDbConnection;
> > >
> > > This does not work as o_Connection is null when it attempts to cast.
> Any
> > > idea why this would be?
> > >
> > > Thanks in advance!
> > >
> > >
> >
> >
>
>