|
-
Oct 29th, 2002, 11:46 AM
#1
Thread Starter
Addicted Member
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.
-
Oct 29th, 2002, 12:10 PM
#2
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:
Dim ar As New System.Configuration.AppSettingsReader()
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:
Public Class AppSettingsWriter
Public Sub SetValue(ByVal key As String, ByVal value As Object)
Dim ds As New DataSet()
ds.ReadXml(GetConfigFilename)
Dim dr() As DataRow = ds.Tables("add").Select(String.Concat("key='", key, "'"))
dr(0).Item("value") = value
ds.WriteXml(GetConfigFilename)
ds.Clear()
End Sub
Private Function GetConfigFilename() As String
Return Reflection.[Assembly].GetExecutingAssembly.Location & ".config"
End Function
End Class
Dim aw As New AppSettingsWriter()
aw.SetValue("gConnection", cnnStr)
-
Oct 30th, 2002, 04:31 AM
#3
Thread Starter
Addicted Member
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.
-
Oct 30th, 2002, 10:21 AM
#4
Thread Starter
Addicted Member
-
Oct 30th, 2002, 11:59 AM
#5
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.
-
Oct 30th, 2002, 12:07 PM
#6
Thread Starter
Addicted Member
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
-
Oct 31st, 2002, 04:29 AM
#7
Thread Starter
Addicted Member
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
-
Oct 31st, 2002, 05:11 AM
#8
Did you make a app config file?
If it still gives you problems just hard could the path in.
-
Nov 4th, 2002, 06:32 AM
#9
Thread Starter
Addicted Member
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??
-
Nov 4th, 2002, 11:16 AM
#10
Thread Starter
Addicted Member
-
Nov 4th, 2002, 12:06 PM
#11
Are you talking about the global.asa (or whatever extension it has now)? Or a web.config file?
-
Nov 5th, 2002, 03:58 AM
#12
Thread Starter
Addicted Member
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|