Last post Sep 04, 2013 01:00 AM by vamsiramo
Member
35 Points
179 Posts
Sep 03, 2013 04:53 PM|gmboat|LINK
Hi Is there a way to fetch a connection string strait from web config instead of doing the following:
using(SqlConnection conn3 = new SqlConnection(@"Data Source=GMBOAT-PC\EMS_AFRICA;Integrated Security=True; User ID=****; password=****"))
All-Star
50831 Points
9895 Posts
Sep 03, 2013 04:57 PM|A2H|LINK
Try like this
Add the connection string in your webconfig
<connectionStrings> <add name="dbconnectionstring" connectionString="Data Source=GMBOAT-PC\EMS_AFRICA;Integrated Security=True; User ID=****; password=****" providerName="System.Data.SqlClient" /> </connectionStrings>
Add a reference to this namespace in your page
using System.Configuration;
Read you connection string using the below code
string MysqlConnectionString = ConfigurationManager.ConnectionStrings["dbconnectionstring"].ConnectionString;
101931 Points
20703 Posts
Sep 03, 2013 05:00 PM|MetalAsp.Net|LINK
Yes indeed. You use the <connectionstrings> section for that.
Refer:
http://www.connectionstrings.com/store-connection-string-in-webconfig/
12 Points
55 Posts
Sep 04, 2013 01:00 AM|vamsiramo|LINK
Hi
Replace below with your db details
<add name="ConnStringName" connectionString="Server=InstanceName;User ID=DBInstanceUserName;Password=DBIsntancePassword;Database=DBName;Trusted_Connection=False;" providerName="System.Data.SqlClient" />
Member
35 Points
179 Posts
Connection strings
Sep 03, 2013 04:53 PM|gmboat|LINK
Hi Is there a way to fetch a connection string strait from web config instead of doing the following:
using(SqlConnection conn3 = new SqlConnection(@"Data Source=GMBOAT-PC\EMS_AFRICA;Integrated Security=True; User ID=****; password=****"))
All-Star
50831 Points
9895 Posts
Re: Connection strings
Sep 03, 2013 04:57 PM|A2H|LINK
Try like this
Add the connection string in your webconfig
Add a reference to this namespace in your page
Read you connection string using the below code
Aje
My Blog | Dotnet Funda
All-Star
101931 Points
20703 Posts
Re: Connection strings
Sep 03, 2013 05:00 PM|MetalAsp.Net|LINK
Yes indeed. You use the <connectionstrings> section for that.
Refer:
http://www.connectionstrings.com/store-connection-string-in-webconfig/
Member
12 Points
55 Posts
Re: Connection strings
Sep 04, 2013 01:00 AM|vamsiramo|LINK
Hi
Replace below with your db details
<add name="ConnStringName" connectionString="Server=InstanceName;User ID=DBInstanceUserName;Password=DBIsntancePassword;Database=DBName;Trusted_Connection=False;" providerName="System.Data.SqlClient" />