Solved

ADO.NET SQL connection string to store connection string

Posted on 2011-09-19
2
329 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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Article by: Kraeven
Introduction Remote Share is a simple remote sharing tool, enabling you to see, add and remove remote or local shares. The application is written in VB.NET targeting the .NET framework 2.0. The source code and the compiled programs have been in…
Microsoft Reports are based on a report definition, which is an XML file that describes data and layout for the report, with a different extension. You can create a client-side report definition language (*.rdlc) file with Visual Studio, and build g…
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…

688 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