Solved

ADO.NET SQL connection string to store connection string

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

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

Suggested Solutions

This tutorial demonstrates one way to create an application that runs without any Forms but still has a GUI presence via an Icon in the System Tray. The magic lies in Inheriting from the ApplicationContext Class and passing that to Application.Ru…
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…
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …

706 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

12 Experts available now in Live!

Get 1:1 Help Now