CodeSmith Community
Your Code. Your Way. Faster!

Dynamically changing connection string on EntityGridView

Latest post 03-15-2007 1:58 PM by david849. 2 replies.
  • 03-13-2007 4:30 PM

    • david849
    • Top 500 Contributor
    • Joined on 03-13-2007
    • Posts 12
    • Points 275

    Dynamically changing connection string on EntityGridView

    Hey guys, tremendous work you all are doing with .netTiers!!

    I need to be able to dynamically change the connection string on my Entity Data Source and for the life of me I can't figure it out. 
    Here is my Entity Data Source and EntityGirdView.

    <dataAms:AMSSiteDrugsViewDataSource ID="dsSiteDrugsView"

    runat="server" EnableCaching="true"

    EnablePaging="true" EnableTransaction="true"

    OnSelecting="dsSiteDrugsView_OnSelecting" />

     

    <dataAms:EntityGridView ID="gv3"

    AllowExportToExcel="false" runat="server"

    DataSourceID="dsSiteDrugsView"

    AllowPaging="true"/>

    In the code-behind I have tried to change the connection string using the code below:
    dsSiteDrugsView.TransactionManager.ConnectionString = "data source=SERVERNAME;initial catalog=XYZ;persist security info=False;user id=XXX;password=XXX;packet size=4096;timeout=300;";

    I have tried to do it in both the page_load method and the dsSiteDrugsView_OnSelecting methods.  In both methods I get the following error:

    Object reference not set to an instance of an object.

    Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

    Exception Details: System.NullReferenceException: Object reference not set to an instance of an object.

    Source Error:

    Line 29: 		{
    Line 30: 			dsSiteDrugsView.TransactionManager.ConnectionString = "data source=xyz;initial catalog=abc;persist security info=False;user id=xxx;password=xxx;packet size=4096;timeout=300;";
    Line 31: 		}
    Line 32: 

    Source File: C:\Data\Projects\AMS\Tools\MedMined.AMS.Tools.WebSite\Test\t.aspx.cs    Line: 30

    Stack Trace:

    [NullReferenceException: Object reference not set to an instance of an object.]
       MedMined.AMS.Tools.WebSite.Test.t.Page_Load(Object sender, EventArgs e) in C:\Data\Projects\AMS\Tools\MedMined.AMS.Tools.WebSite\Test\t.aspx.cs:30
       System.Web.Util.CalliHelper.EventArgFunctionCaller(IntPtr fp, Object o, Object t, EventArgs e) +15
       System.Web.Util.CalliEventHandlerDelegateProxy.Callback(Object sender, EventArgs e) +34
       System.Web.UI.Control.OnLoad(EventArgs e) +99
       System.Web.UI.Control.LoadRecursive() +47
       System.Web
     

    Anyone have any ideas on how I can accomplish my goal of dynamically changing the connection string on the Entity Data Source??

    Thanks!!!

    David

    • Post Points: 35
  • 03-13-2007 5:06 PM In reply to

    • mike123
    • Top 10 Contributor
    • Joined on 02-25-2005
    • Toronto, Ontario
    • Posts 726
    • Points 16,910

    Re: Dynamically changing connection string on EntityGridView

    Reply |Contact |Answer

    Mike Shatny
    --------------------------------------------------------------
    Member of the .netTiers team http://www.nettiers.com
    --------------------------------------------------------------

    • Post Points: 35
  • 03-15-2007 1:58 PM In reply to

    • david849
    • Top 500 Contributor
    • Joined on 03-13-2007
    • Posts 12
    • Points 275

    Re: Dynamically changing connection string on EntityGridView

    • Post Points: 5
Page 1 of 1 (3 items) | RSS
Copyright © 2008 CodeSmith Tools, LLC
Powered by Community Server (Commercial Edition), by Telligent Systems