Reflection with SqlConnection

  • Thread starter Thread starter WebDevHokie
  • Start date Start date
W

WebDevHokie

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!
 
I copied your code and it works fine here. Look for another problem past the
line that is doing the cast.

Kathleen
 
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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top