Solved

ADO.NET SQL connection string to store connection string

Posted on 2011-09-19
2
326 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

If you're writing a .NET application to connect to an Access .mdb database and use pre-existing queries that require parameters, you've come to the right place! Let's say the pre-existing query(qryCust) in Access takes a Date as a parameter and l…
Creating an analog clock UserControl seems fairly straight forward.  It is, after all, essentially just a circle with several lines in it!  Two common approaches for rendering an analog clock typically involve either manually calculating points with…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

730 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