but I have been using on my asp.net code the following format to create manually a connection string by code
Dim con As SqlConnection
Dim cmd As SqlCommand
con = New SqlConnection("Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\dayabasename.mdf;Integrated Security=True;User Instance=True")
con.Open()
cmd = New SqlCommand("dbo.AddPMUpdate", con)
cmd.CommandType = CommandType.StoredProcedure
cmd.Parameters.AddWithValue("@Title", TBTitle.Text)
cmd.Parameters.AddWithValue("@Description", TBDescription.Text)
cmd.ExecuteNonQuery()
con.Close()
GridView1.DataBind()
TBTitle.Text = ""
TBDescription.Text = ""
Catch ex As Exception
LBMessage.Text = ex.Message
now my application has been published, and I got and erroe in each page that I created a manual connection string by code
I would appreciate if you show me how to read the connection string from my web.config to my code.
Thanks in advance, your help will be appreciated....!!!!
jpuga
Member
69 Points
103 Posts
reading a web.config connection string from asp.net code
May 09, 2012 02:57 PM|LINK
Hi All
my web.config connection string is:
but I have been using on my asp.net code the following format to create manually a connection string by code
Dim con As SqlConnection Dim cmd As SqlCommand con = New SqlConnection("Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\dayabasename.mdf;Integrated Security=True;User Instance=True") con.Open() cmd = New SqlCommand("dbo.AddPMUpdate", con) cmd.CommandType = CommandType.StoredProcedure cmd.Parameters.AddWithValue("@Title", TBTitle.Text) cmd.Parameters.AddWithValue("@Description", TBDescription.Text) cmd.ExecuteNonQuery() con.Close() GridView1.DataBind() TBTitle.Text = "" TBDescription.Text = "" Catch ex As Exception LBMessage.Text = ex.Messagenow my application has been published, and I got and erroe in each page that I created a manual connection string by code
I would appreciate if you show me how to read the connection string from my web.config to my code.
Thanks in advance, your help will be appreciated....!!!!
HeartattacK
All-Star
55262 Points
5917 Posts
Moderator
MVP
Re: reading a web.config connection string from asp.net code
May 09, 2012 03:04 PM|LINK
Reference System.Configuration and then you can access it by:
blog: www.heartysoft.com
twitter: @ashic
jpuga
Member
69 Points
103 Posts
Re: reading a web.config connection string from asp.net code
May 09, 2012 03:18 PM|LINK
I tried with this format
HeartattacK
All-Star
55262 Points
5917 Posts
Moderator
MVP
Re: reading a web.config connection string from asp.net code
May 09, 2012 03:20 PM|LINK
Ahh...you're on VB.NET:
ConfigurationManager.ConnectionStrings("Conectionstring").ConnectionString
blog: www.heartysoft.com
twitter: @ashic
jpuga
Member
69 Points
103 Posts
Re: reading a web.config connection string from asp.net code
May 09, 2012 03:44 PM|LINK
Thanks a lot now works......