I am new in the web development world and I would like to create a variable in the web.config file so that I can use it in the .NET portion of the web.api
I found the following tutorials on how to do that :
Setting up connection string in ASP.NET to SQL SERVER
And
http://www.connectionstrings.com/Articles/Show/store-connection-string-in-web-config
I have the following question , I don t have a database to connect the string to(I will only use it in the web config so that I can easily change the string without having to go through code . so assuming that I am using it in the following way :
<add name="ConnStringDb1" connectionString="Data Source=localhost;Initial Catalog=YourDataBaseName;Integrated Security=True;" providerName="System.Data.SqlClient" />
What should I have in the connectionString
and the providerName
?
If I understand what you want to do, it sounds like you don't want to use a connection string at all. Instead, use the Application Settings sections of your web.config file. For example
<configuration>
<system.web> ... </system.web>
<appSettings>
<add key="MyAppSetting" value="A test value." />
</appSettings>
</configuration>
This can then be used in your code by getting the value of
System.Configuration.ConfigurationManager.AppSettings["MyAppSetting"]
(C#) or
System.Configuration.ConfigurationManager.AppSettings("MyAppSetting")
(VB)
See MSDN for more information, or just search online for "asp.net AppSettings".
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With