my.settings website

H

HaVoK

Hello,


i am developing a website and want to use the connectionstring of my
web.config in other sites.
i have a connectionstring in my web.config like this:
<configuration>
<appSettings/>
<connectionStrings>
<add name="Test.My.Settings.conni" connectionString="*******"
providerName="System.Data.SqlClient" />
</connectionStrings>

i have found a lot of examples for windows applications like this.
connection = My.Settings.conni

but the parameter My.Settings is not available in my Website-Project.
only my.user, e.g.

How can i use this connection in my Website? is there any way?


Best regards
Benjamin
 
J

Juan T. Llibre

re:
ConfigurationManager.ConnectionStrings["Test.My.Settings.conni"]

HaVoK could also use :

<%$ ConnectionStrings:Test.My.Settings.conni%>

HaVoK probably shouldn't use the "My.Settings" name.

It's confusing, since there's a programming feature named
"My.Settings", which can't be used in a web application.

I'd use something like :
ConnString="<%$ ConnectionStrings:Conn %>"
in the SqlConnection.

or, importing System.Web.Configuration :
string conn = WebConfigurationManager.ConnectionStrings["conn"].ConnectionString;

You could even use :
String conn = ConfigurationManager.ConnectionStrings["Conn"].ConnectionString;

or
SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["conn"].ToString());
....as long as you import System.Configuration.

This last one is functionally the same as your example.






Milosz Skalecki said:
ConfigurationManager.ConnectionStrings["Test.My.Settings.conni"]
--
Milosz Skalecki
MCP, MCAD


HaVoK said:
Hello,


i am developing a website and want to use the connectionstring of my
web.config in other sites.
i have a connectionstring in my web.config like this:
<configuration>
<appSettings/>
<connectionStrings>
<add name="Test.My.Settings.conni" connectionString="*******"
providerName="System.Data.SqlClient" />
</connectionStrings>

i have found a lot of examples for windows applications like this.
connection = My.Settings.conni

but the parameter My.Settings is not available in my Website-Project.
only my.user, e.g.

How can i use this connection in my Website? is there any way?


Best regards
Benjamin
 
H

HaVoK

thanks a lot for the fast and good answers.
that was exaxtly what i am looking for.

another question: if i want to set the server dynamicly for example
like tihs.../main.aspx?server=bgu03
is there any way to generate the serverstring automaticly by looking at
the url extension or anything else?

i want to have the possibility for the users to select if they want to
go to a test-server or the production-server.
Thanks for your help.

Best regards.
Benjamin
 

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
474,430
Messages
2,571,676
Members
48,796
Latest member
Greg L.

Latest Threads

Top