my.settings website

  • Thread starter Thread starter HaVoK
  • Start date Start date
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
 
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.





Juan T. Llibre, asp.net MVP
asp.net faq : http://asp.net.do/faq/
foros de asp.net, en español : http://asp.net.do/foros/
===================================
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
 
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
 
Back
Top