Professional Web Applications Themes

Reflection and SqlConnection - ASP.NET General

It is in the System.Data assembly. I tried System.Data.SqlClient first and then switched to System.Data and that worked. In the debugger, it shows me that it creates the SqlConnection correctly, its just when it tries to cast it fails. Thanks WebDevHokie "Tu-Thach" <tuthach> wrote in message news:00b301c34711$3e8dea90$a401280aphx.gbl... > Could it be that the assembly for SqlClient is > System.Data.SqlClient.dll instead of just System.Data.dll? > > Tu-Thach > > >-----Original Message----- > >I am using reflection to create a data access > component. I have the > >following code: > > > > SqlConnection o_Temp = new SqlConnection(); > > System.Data.IDbConnection ...

  1. #1

    Default Re: Reflection and SqlConnection

    It is in the System.Data assembly. I tried System.Data.SqlClient first and
    then switched to System.Data and that worked.

    In the debugger, it shows me that it creates the SqlConnection correctly,
    its just when it tries to cast it fails.

    Thanks

    WebDevHokie


    "Tu-Thach" <tuthach> wrote in message
    news:00b301c34711$3e8dea90$a401280aphx.gbl...
    > Could it be that the assembly for SqlClient is
    > System.Data.SqlClient.dll instead of just System.Data.dll?
    >
    > Tu-Thach
    >
    > >-----Original Message-----
    > >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!
    > >
    > >
    > >.
    > >

    WebDevHokie Guest

  2. #2

    Default Re: Reflection and SqlConnection

    I just found some interesting information. I tried running this same code
    on a co-workers computer and it works fine. The only difference between us
    is that I have both the 1.0 and 1.1 frameworks on my box. The other
    gentleman has only the 1.0 framework. Would this cause a problem?

    I set all my mappings to use the 1.0.3705 framework.

    Thanks

    WebDevHokie

    "WebDevHokie" <mwitczakrkeng.com> wrote in message
    news:%23$pE%239wRDHA.212TK2MSFTNGP10.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("Sy stem.Data");
    > object o_Temp2 =
    > o_Assembly.CreateInstance("System.Data.SqlClient.S qlConnection");
    > 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!
    >
    >

    WebDevHokie Guest

Similar Threads

  1. help with sqlconnection!!
    By Shakazulu89 in forum Macromedia Flex General Discussion
    Replies: 7
    Last Post: April 15th, 09:45 AM
  2. SqlConnection Problem
    By Calvin Willman in forum Dreamweaver AppDev
    Replies: 0
    Last Post: April 23rd, 02:09 PM
  3. SqlConnection, SqlCommand
    By Donnie Darko in forum ASP.NET Web Services
    Replies: 3
    Last Post: July 21st, 02:46 PM
  4. SQLConnection.Open() in a WebService
    By Stephen in forum ASP.NET Web Services
    Replies: 3
    Last Post: July 19th, 07:23 PM
  5. Access Denied to sqlConnection
    By John Giblin in forum ASP.NET Security
    Replies: 1
    Last Post: July 17th, 03:41 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139