In the line
string connectionstr = ConfigurationManager.Conne
that ConnectionString1 is ConnectionString.
And the Exception I am getting is
"Object Reference Not set to an instance of the object"
Main Topics
Browse All TopicsHi Experts,
I have created a Outlook Shared Add-in.I am creating coneection to my sql database.
I am able to create connection but how to store it in a config file and access the connectionstring from there?
Currently I am trying below code but it is throwing an exception.
This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.
Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.
If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.
Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.
Access the answers to your technology questions today.
30-day free trial. Register in 60 seconds.
Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Try it out and discover for yourself.
30-day free trial. Register in 60 seconds.
Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.
Hi there.
I just used the name 'MyConnectionString' in the code as an example, but to copy your code, you should rename this:
<configuration>
<connectionStrings>
<add name="MyConnection" connectionString="this is a test"/>
</connectionStrings>
</configu
to this:
<configuration>
<connectionStrings>
<add name="ConnectionString" connectionString="Data Source=192.168.40.46;Initi
</connectionStrings>
</configu
As per gauthampj's advice.
Cheers
Jas.
Hi.
In response to t0ni's comment, the best way to store the connection string is to encrypt it in the config file. Here's a link that explains this:
http://www.4guysfromr
Having the connection string in the code is suicide unless the code is obfuscated, since using .NET Reflector would allow anyone to view the code for the app and get the connection string details.
Also storing the connection string in the app.config file unencrypted is risky, since anyone can open the file in the Notepad and have a look.
Cheers.
Jas.
Hi there.
The app.config way of reading the config should work, if it;s not, then I also think that the app.config is in the wrong folder and your code cannot find it.
One other way to get around this is to put your connection string in the machine.config file. I have to go now, but here is a link that explains how to use machine.config:
http://msdn
http://f
Chee
Jas.
I have created a new class named ConfigurationSettings.
I have made little modification to it.
as my app.config looks like
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<connectionStrings>
<add name="MyConnection" connectionString="coneecti
</connectionStrings>
</configuration>
Now what next?
Business Accounts
Answer for Membership
by: MrClyfarPosted on 2009-04-13 at 04:31:33ID: 24129025
Hi there.
Try this instead.
Cheers.
Jas.
Select allOpen in new window