473,386 Members | 1,830 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

using connection stirng

hi....

How to use the connection string specified in app.config file in a windows form in c#. Please help.

Regards,
Aradhana
Oct 13 '08 #1
3 1315
teddarr
143 100+
include using System.Configuration;

Then put your connection string in the web.config file in the connectionStrings node.

example:

<add name="nameOfConString" connectionString="Server=serverName;Database=DbNam e;" providerName="System.Data.SqlClient"/>

After that you will need to add a reference to either Windows.Configuration or System.Configuration.

After that add a line in your class to give a global variable, or declare it in each method, or the constuctor...whichever you prefer.

The line is:

Dim conn As New SqlConnection(ConfigurationManager.ConnectionStrin gs("nameOfConString").ConnectionString)

or

SqlConnection conn = ConfigurationManager.ConnectionStrings("nameOfConS tring").ConnectionString;

It's a very handy technique that you will find yourself using from here on out.
Oct 13 '08 #2
Curtis Rutland
3,256 Expert 2GB
in C# that would be:
Expand|Select|Wrap|Line Numbers
  1. SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["name"].ConnectionString;
Oct 13 '08 #3
teddarr
143 100+
see what vb is doing to my brain.

Thanks for the correction. :)
Oct 13 '08 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

11
by: Bob | last post by:
In our new .NET web applications, we try to limit the use of SqlConnection to just one instance per page, even if there are multiple accesses to various queries. The thinking behind is that this...
0
by: Bernie | last post by:
Hi All, I have a weird problem with using flash on aspx pages. It goes like this: I have some links with query string parameters in the page. The same links appear as regular "a href" and also...
8
by: Pierson C | last post by:
I am developing on a website that is utilizing SQL Server 2000. Shortly after deploying the site, we began having timeout issues due to the max connections. 1st instinct was to diligently tidy...
4
by: Isambella via DotNetMonster.com | last post by:
Hi, I have in a string some XML and I want that xml to be transformed using XSLT file (I found the way how to transform a xml file using XSLT but I didn’t find a way how to transform using...
2
by: mfresa | last post by:
I'm a newbie to VB.NET, and so far have used the wizard to generate connection strings to an Oracle database. In the wizard, the userid and password are hard coded into the connection string. Is...
2
by: almurph | last post by:
Intern Strings - am I usingthem right. I have heard a lot about intern string - so I wanted to use them to increas e speed of processing. I have a hastable that I am using to parse a string...
8
by: Andrew Robinson | last post by:
Are these two equivalent? Is one better than the other? I tend to go with #1 but started wondering.... Thanks, 1: using (SqlConnection cn = new SqlConnection(DataConnection)) using...
1
by: Anonieko | last post by:
Understanding and Using Exceptions (this is a really long post...only read it if you (a) don't know what try/catch is OR (b) actually write catch(Exception ex) or catch{ }) The first thing I...
2
by: ad | last post by:
I use a TextBox for to enter an string. How can I determiniate if the stirng is Chinese or English?
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.