Results 1 to 12 of 12

Thread: one hard question (the other has been sloved)

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Oct 2002
    Posts
    128

    one hard question (the other has been sloved)

    I have a web application, this application access an sql server. the database will be moved from time to time.

    I need to know if it is possible to type in the location of the database server into a text box or something, this will only be visible to the Admin group.

  2. #2
    Your Ad Here! Edneeis's Avatar
    Join Date
    Feb 2000
    Location
    Moreno Valley, CA (SoCal)
    Posts
    7,339
    Ok here is what I would do. I would put an appSetting in the web.config file that is the current connection string. Then you have all your data get that setting and use that connection string to connect (using the appsettingreader). Then I would have a page that only the admin group can reach that has the textbox on it. Then after they enter the new connection string into the textbox and hit 'submit' or whatever the page writes the new connection string to the web.config file. This would work for a non web config file and I am pretty sure it would work for a web config file also.

    To add appSettings to a config file you make an appSettings (which is case sensitive) section in the config file under configuration. Then for each value you enter an add section with key and value attributes.

    <configuration>
    <appSettings>
    <add key="gConnection" value="My ConnectionString Here" />
    </appSettings>
    </configuration>

    To retrieve the value from the config file in code you'd use:
    VB Code:
    1. Dim ar As New System.Configuration.AppSettingsReader()
    2. Dim cnnStr As String=ar.GetValue("gConnection", GetType(String))

    To write to the config file I didn't find a built in AppSettingsWriter so I made one, here it is and the syntax to use it:
    VB Code:
    1. Public Class AppSettingsWriter
    2.  
    3.     Public Sub SetValue(ByVal key As String, ByVal value As Object)
    4.         Dim ds As New DataSet()
    5.         ds.ReadXml(GetConfigFilename)
    6.         Dim dr() As DataRow = ds.Tables("add").Select(String.Concat("key='", key, "'"))
    7.         dr(0).Item("value") = value
    8.         ds.WriteXml(GetConfigFilename)
    9.         ds.Clear()
    10.     End Sub
    11.  
    12.     Private Function GetConfigFilename() As String
    13.         Return Reflection.[Assembly].GetExecutingAssembly.Location & ".config"
    14.     End Function
    15.  
    16. End Class
    17.  
    18. Dim aw As New AppSettingsWriter()
    19. aw.SetValue("gConnection", cnnStr)

  3. #3

    Thread Starter
    Addicted Member
    Join Date
    Oct 2002
    Posts
    128
    will this affect the SqlDataAdtapters that i have created?beacause i had to define the server in setting them up

    also the textbox i will use will be on a webpage that all the users can acces but it is only visible if the admin logs in.

    what part of the code you provided will be used in the default.aspx file and what for the btn_Submit On Click?

    the function you provided does work beacuse its trying to find the web.config file from the local machine and i need it to look in the server.

    please send an update...
    Last edited by tmashley; Oct 30th, 2002 at 11:59 AM.

  4. #4

    Thread Starter
    Addicted Member
    Join Date
    Oct 2002
    Posts
    128
    bump

  5. #5
    Your Ad Here! Edneeis's Avatar
    Join Date
    Feb 2000
    Location
    Moreno Valley, CA (SoCal)
    Posts
    7,339
    Well you should probably read a tutorial on work with data in code. It sounds like you used the wizard to setup the data connection. There is nothing wrong in that but if you are going to be changing it then you'll need to do that in code. Where ever it loads the connection string that you set you'll have to change it to load the connection string from the config file.

    As for the OnClick of the button by the textbox. That will need to write the textbox contents to the config file.

  6. #6

    Thread Starter
    Addicted Member
    Join Date
    Oct 2002
    Posts
    128
    i have set the connection in the componant to the web.config settings, i works ok.

    this is how i understand the OnClick to work:

    Code:
    Private Sub btnDbServer_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnDbServer.Click
            lblDbServer.Visible = False
            txtDBServer.Visible = False
            btnDbServer.Visible = False
            Dim aw As New AppSettinsWriter()
            aw.SetValue("conSystemStatus.ConnectionString", "Data Source=" & txtDBServer.Text & "localhost;Integrated Security=SSPI;Initial Catalog=SystemStatus")
        End Sub
    make sence?

    i am not sure the location of the web.config line in the function works

  7. #7

    Thread Starter
    Addicted Member
    Join Date
    Oct 2002
    Posts
    128
    dumb + this:

    i am getting an error when i try to run the function GetConfigFilename....



    Server Error in '/IISapps' Application.
    --------------------------------------------------------------------------------

    Could not find file "c:\winnt\microsoft.net\framework\v1.0.3705\temporary asp.net files\iisapps\5f198316\fddf267\assembly\dl\865ea49a\3065e34d_bf80c201\iisapps.dll.config".
    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.IO.FileNotFoundException: Could not find file "c:\winnt\microsoft.net\framework\v1.0.3705\temporary asp.net files\iisapps\5f198316\fddf267\assembly\dl\865ea49a\3065e34d_bf80c201\iisapps.dll.config".

    Source Error:

    An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.

    Stack Trace:


    [FileNotFoundException: Could not find file "c:\winnt\microsoft.net\framework\v1.0.3705\temporary asp.net files\iisapps\5f198316\fddf267\assembly\dl\865ea49a\3065e34d_bf80c201\iisapps.dll.config".]
    System.IO.__Error.WinIOError(Int32 errorCode, String str) +181
    System.IO.FileStream..ctor(String path, FileMode mode, FileAccess access, FileShare share, Int32 bufferSize, Boolean useAsync, String msgPath, Boolean bFromProxy) +859
    System.IO.FileStream..ctor(String path, FileMode mode, FileAccess access, FileShare share) +45
    System.Xml.XmlDownloadManager.GetStream(Uri uri, ICredentials credentials) +73
    System.Xml.XmlUrlResolver.GetEntity(Uri absoluteUri, String role, Type ofObjectToReturn) +55
    System.Xml.XmlTextReader.CreateScanner() +170
    System.Xml.XmlTextReader.Init() +23
    System.Xml.XmlTextReader.Read() +530
    System.Xml.XmlReader.MoveToContent() +75
    System.Data.DataSet.ReadXml(XmlReader reader) +133
    System.Data.DataSet.ReadXml(String fileName) +60
    AppSettinsWriter.SetValue(String key, Object value) in I:\reg\AppSettingsWriter.aspx.vb:29
    AppSettinsWriter.btnDbServer_Click(Object sender, EventArgs e) in I:\reg\AppSettingsWriter.aspx.vb:45
    System.Web.UI.WebControls.Button.OnClick(EventArgs e) +108
    System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument) +57
    System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument) +18
    System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData) +33
    System.Web.UI.Page.ProcessRequestMain() +1263




    --------------------------------------------------------------------------------
    Version Information: Microsoft .NET Framework Version:1.0.3705.209; ASP.NET Version:1.0.3705.0

  8. #8
    Your Ad Here! Edneeis's Avatar
    Join Date
    Feb 2000
    Location
    Moreno Valley, CA (SoCal)
    Posts
    7,339
    Did you make a app config file?

    If it still gives you problems just hard could the path in.

  9. #9

    Thread Starter
    Addicted Member
    Join Date
    Oct 2002
    Posts
    128
    the ("add") section of the web.config file, i think, is causing the error below. because i have other "adds" in the file...

    <compilation>
    <assemblies>
    <add assembly="CrystalDecisions.CrystalReports..../>
    <add assembly="CrystalDecisions.ReportSource..../>
    <add assembly="CrystalDecisions.Shared..../>
    <add assembly="CrystalDecisions.Web..../>
    </assemblies>
    </compilation>

    and

    <appSettings>
    <add key="gConnection" value="data source=localhost../>
    </appSettings>

    Error that now appears:

    Server Error in '/IISapps' Application.
    --------------------------------------------------------------------------------

    The same table (add) cannot be the child table in two nested relations.
    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.ArgumentException: The same table (add) cannot be the child table in two nested relations.

    any ideas??

  10. #10

    Thread Starter
    Addicted Member
    Join Date
    Oct 2002
    Posts
    128
    bump

  11. #11
    Your Ad Here! Edneeis's Avatar
    Join Date
    Feb 2000
    Location
    Moreno Valley, CA (SoCal)
    Posts
    7,339
    Are you talking about the global.asa (or whatever extension it has now)? Or a web.config file?

  12. #12

    Thread Starter
    Addicted Member
    Join Date
    Oct 2002
    Posts
    128
    web.config, i have been given some advice: add a custom config file, i am going to try that now

Posting Permissions

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



Click Here to Expand Forum to Full Width