Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

ADO.NET SQL connection string to store connection string

Posted on 2011-09-19
2
Medium Priority
?
339 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 1000 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

I think the Typed DataTable and Typed DataSet are very good options when working with data, but I don't like auto-generated code. First, I create an Abstract Class for my DataTables Common Code.  This class Inherits from DataTable. Also, it can …
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…
Video by: ITPro.TV
In this episode Don builds upon the troubleshooting techniques by demonstrating how to properly monitor a vSphere deployment to detect problems before they occur. He begins the show using tools found within the vSphere suite as ends the show demonst…
In this video, Percona Director of Solution Engineering Jon Tobin discusses the function and features of Percona Server for MongoDB. How Percona can help Percona can help you determine if Percona Server for MongoDB is the right solution for …
Suggested Courses

604 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