Connection String not initialized

R

rodchar

hey all,

SqlDataAdapter da = new SqlDataAdapter(@"Select * from Products",
ConfigurationSettings.AppSettings["NorthwindConnectionString"]);
DataTable tbl = new DataTable();
da.Fill(tbl);

Can someone please tell me what I'm missing?

thanks,
rodchar
 
S

Scott Roberts

Connection strings are *typically* stored in the <ConnectionStrings> section
of web.config, not <AppSettings>. If that's the case, try this:

string dbConnection =
ConfigurationManager.ConnectionStrings["NorthwindConnectionString"].ConnectionString;
 
M

Milosz Skalecki [MCAD]

Hi there Rod,

Don't get me wrong but I would suggest you to start using every's
programmer's best friend - debugger. In this particular case seems connection
string is not defined in app settings, maybe there's a typo in the web.config
or it's defined but under connectionStrings section. Debugger will save you
time as you can pick up bugs much quicker than asking questions and waiting
for the reply.

Have a good night
 
R

rodchar

You are right that it's in the connectionStrings section, how do you get to
that?

Milosz Skalecki said:
Hi there Rod,

Don't get me wrong but I would suggest you to start using every's
programmer's best friend - debugger. In this particular case seems connection
string is not defined in app settings, maybe there's a typo in the web.config
or it's defined but under connectionStrings section. Debugger will save you
time as you can pick up bugs much quicker than asking questions and waiting
for the reply.

Have a good night
--
Milosz


rodchar said:
hey all,

SqlDataAdapter da = new SqlDataAdapter(@"Select * from Products",
ConfigurationSettings.AppSettings["NorthwindConnectionString"]);
DataTable tbl = new DataTable();
da.Fill(tbl);

Can someone please tell me what I'm missing?

thanks,
rodchar
 
D

David Wier

What exactly do you mean by 'how do you get to that?"
The web.config file is a file, like any other in the root directory of the
website, that you can open and edit.

David Wier
http://aspnet101.com
http://iWritePro.com - One click PDF, convert .doc/.rtf/.txt to HTML with no
bloated markup


rodchar said:
You are right that it's in the connectionStrings section, how do you get
to
that?

Milosz Skalecki said:
Hi there Rod,

Don't get me wrong but I would suggest you to start using every's
programmer's best friend - debugger. In this particular case seems
connection
string is not defined in app settings, maybe there's a typo in the
web.config
or it's defined but under connectionStrings section. Debugger will save
you
time as you can pick up bugs much quicker than asking questions and
waiting
for the reply.

Have a good night
--
Milosz


rodchar said:
hey all,

SqlDataAdapter da = new SqlDataAdapter(@"Select * from Products",
ConfigurationSettings.AppSettings["NorthwindConnectionString"]);
DataTable tbl = new DataTable();
da.Fill(tbl);

Can someone please tell me what I'm missing?

thanks,
rodchar
 
S

Scott Roberts

string dbConnection =
ConfigurationManager.ConnectionStrings["NorthwindConnectionString"].ConnectionString;


rodchar said:
You are right that it's in the connectionStrings section, how do you get
to
that?

Milosz Skalecki said:
Hi there Rod,

Don't get me wrong but I would suggest you to start using every's
programmer's best friend - debugger. In this particular case seems
connection
string is not defined in app settings, maybe there's a typo in the
web.config
or it's defined but under connectionStrings section. Debugger will save
you
time as you can pick up bugs much quicker than asking questions and
waiting
for the reply.

Have a good night
--
Milosz


rodchar said:
hey all,

SqlDataAdapter da = new SqlDataAdapter(@"Select * from Products",
ConfigurationSettings.AppSettings["NorthwindConnectionString"]);
DataTable tbl = new DataTable();
da.Fill(tbl);

Can someone please tell me what I'm missing?

thanks,
rodchar
 
M

Milosz Skalecki [MCAD]

Howdy,

c#
System.Configuration.ConfigurationManager.ConnectionStrings["ConnectionStringName"].ConnectionString

vb.net
System.Configuration.ConfigurationManager.ConnectionStrings("ConnectionStringName").ConnectionString

HTH
--
Milosz


rodchar said:
You are right that it's in the connectionStrings section, how do you get to
that?

Milosz Skalecki said:
Hi there Rod,

Don't get me wrong but I would suggest you to start using every's
programmer's best friend - debugger. In this particular case seems connection
string is not defined in app settings, maybe there's a typo in the web.config
or it's defined but under connectionStrings section. Debugger will save you
time as you can pick up bugs much quicker than asking questions and waiting
for the reply.

Have a good night
--
Milosz


rodchar said:
hey all,

SqlDataAdapter da = new SqlDataAdapter(@"Select * from Products",
ConfigurationSettings.AppSettings["NorthwindConnectionString"]);
DataTable tbl = new DataTable();
da.Fill(tbl);

Can someone please tell me what I'm missing?

thanks,
rodchar
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,055
Latest member
SlimSparkKetoACVReview

Latest Threads

Top