Solved

ADO.NET SQL connection string to store connection string

Posted on 2011-09-19
2
305 Views
Last Modified: 2012-05-12
Hi Experts

Should be an easy one, I need some VB.net code to get the connection string from a web.config file.

In my web.config file I have a stored connection string

<connectionStrings>
  <add name="MyConnectionString" connectionString="Data Source=MyServer;Initial Catalog=MyDb;Integrated Security=True"
   providerName="System.Data.SqlClient" />
 </connectionStrings>

I have a vb.net page that I want to create a SQL server connection using the connection string above.


so far I have

Using connection As New SqlConnection("ConnectionStrings:MyConnectionString"")

the syntax above is not working, I cant remember for the life of me how to do this!

Many thanks

0
Comment
Question by:MrDavidThorn
2 Comments
 

Author Comment

by:MrDavidThorn
ID: 36560683
after not much google searcihing I found

        Dim ConnString = ConfigurationManager.ConnectionStrings("MyConnectionString")
        Dim StrConnString = ConnString.ConnectionString

- Is there a way I can use use the above but with public variables?
0
 
LVL 22

Accepted Solution

by:
pivar earned 250 total points
ID: 36560705
Hi,

I think the parameter given to SqlConnection should be the actual connectionstring, so something like

Using connection As New SqlConnection(ConfigurationManager.ConnectionStrings("MyConnectionString").ConnectionString())

/peter
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction When many people think of the WebBrowser (http://msdn.microsoft.com/en-us/library/2te2y1x6%28v=VS.85%29.aspx) control, they immediately think of a control which allows the viewing and navigation of web pages. While this is true, it's a…
It’s quite interesting for me as I worked with Excel using vb.net for some time. Here are some topics which I know want to share with others whom this might help. First of all if you are working with Excel then you need to Download the Following …
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…
This is a video describing the growing solar energy use in Utah. This is a topic that greatly interests me and so I decided to produce a video about it.

929 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now