Writing connection string in web.config

W

WT

Hello,

I am writing a Web install project and I want to get the connection string
from user and write it in the web.config of the installed web site.
As the Websetup is a windows program, I use a windows program to get the
string and I don't know if I can use the WebConfigurationManager API to read
and write my web config from a windows program.
What is the prefered .NET 2 way to handle this necessary install problem
without asking users to open web.config and write the connection stri ng in
the ConnectionString section by hand..

Thanks for help
CS
 
M

Marina Levit [MVP]

If you put it into web.config, that will immediately restart asp.net. I
would not recommend doing this.

If the user is going to change this on the fly, I would create a separate
file, and write to it. Just make sure that it is secured such that someone
can't create an http request and ask for it. I think maybe .config files
are protected automatically, so maybe you can call it myConnString.config,
and have IIS take care of this for you (double check this).
 
W

WT

Thanks for answer but you have not understood my problem, may be badly
explained, my fault.

I am installing a web site using a web setup program built with VS2005.
Nothing is running, the setup process has just copied the files in the
desired server folder, and the GetLicence Dialog is ran to get the SQL
connection string from user.

CS
 
M

Marina Levit [MVP]

Oh, I see. Sorry for misunderstanding.

As far as I know, there is no API for writing to the .config file. You'll
need to just load it up into an XML dom, manipulate it, and save it back.
 
E

Edwin Knoppert

I am writing a Web install project and I want to get the connection string
from user and write it in the web.config
Why?
Relative folder is allowed nativly.
 
W

WT

What do you call relative folder ?
Sometime several SQL servers are available, and different connection
strings.
CS
 
E

Edwin Knoppert

The original post was unclear to me.
I see you really want to write it, and not using
datasource=|DataDirectory|... stuff.
Ok.
:)
 
W

Walter Wang [MSFT]

Hi,

Thank you for your post!

Although in .NET 2.0 we can use WebConfigurationManager API to read/write
the web.config via code, currently
WebConfigurationManager.OpenWebConfiguration() can only use virtual path to
access web.config. Since you are running a Windows application, I'm afraid
this approach will not be applicable.


Regards,
Walter Wang
Microsoft Online Community Support

==================================================
When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.
==================================================

This posting is provided "AS IS" with no warranties, and confers no rights.
 
W

Walter Wang [MSFT]

Thank you for your update.

Please feel free to post here if you have any question about the XML
approach.

Regards,
Walter Wang
Microsoft Online Community Support

==================================================
When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.
==================================================

This posting is provided "AS IS" with no warranties, and confers no rights.
 

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

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,070
Latest member
BiogenixGummies

Latest Threads

Top