Solved

Connection string for .NET Windows forms

Posted on 2006-11-27
8
242 Views
Last Modified: 2011-10-03
Hi,

I'm working on an ASP.NET app but some parts of this application may be used for Windows forms later on too (objects, etc.). How can I specify the connection string to the SQL Server database in a single place so that if the SQL server database is moved to a different location, I only have to change the connection string in one place? That is, I wouldn't have to update the connection string for every single computer that uses the Windows forms app. I haven't worked with Windows forms before, so I'm not sure if this is even possible, but any help will be appreciated. Please let me know if you need more information or if this doesn't make sense at all.

Thanks.
0
Comment
Question by:cindyrod
  • 3
  • 3
8 Comments
 
LVL 10

Expert Comment

by:tpwells
ID: 18018734
You could create a web service that the Forms applications would consume to retrieve their connection string.

You could also store the connection string in an configuration file on the user machine that you can easily update without re-compiling your programs.

With the scenario you have suggested the application is intended for a network environment so it would be possible to place the connection string into a file that is on a network share and load the it from there.

The first thing to keep in mind, since this is a connection string, is to keep it secured so not just anyone can read it and get into your databases with other applications. I would advise using an encryption method to encrypt the Connection String in any of the above methods to help ensure that the string is kept safe from all but the most determined evil-doers.
0
 
LVL 1

Author Comment

by:cindyrod
ID: 18019850
I've never worked with Web Services. How could I write one to just return the connection string? How would I access it from the Windows forms?

Thank you!
0
 
LVL 10

Expert Comment

by:tpwells
ID: 18020675
Here is a tutorial on how to create a Web Service:
VB.NET: http://abstractvb.com/code.asp?A=1004
C#: http://www.codeproject.com/cs/webservices/myservice.asp

Here is how to link your windows application to a WebService:
In VB but works same in C#:
http://www.codeguru.com/vb/vb_internet/webservices/article.php/c4813/
0
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.

 
LVL 10

Expert Comment

by:Kinger247
ID: 18027780
One bit of advice, make sure your enrypt the connection string.
Anyone will be able to view the soap message ;)
0
 
LVL 1

Author Comment

by:cindyrod
ID: 18078578
Thanks for the info. After talking to someone here, I won't be able to use Web Services because they may consume many resources on the server, especially since it would be used every time anyone wants to connect to the database. Would it be possible to have an XML file on the server and just use it for both web applications and windows forms? Would this affect performance?

Thanks!!
0
 
LVL 10

Accepted Solution

by:
tpwells earned 500 total points
ID: 18084165
You can place it on a server.

It will have to be in a place that all users and systems have access to it.

You will definately want to secure the file with encryption to protect your database credentials.

I would also make the file ReadOnly and when opening it with a FileStream to open it with FileMode.Open, FileAccess.Read, FileShare.Read.

If you go with this approach you can set the web applications to load the file from other servers. However, I would recommend setting those settings on the web application's server so that the web app is not dependent on another system and will still function as long as the database and web servers are running.

Performance will only be affected by the speed of your network. The only other factors to increase speed would be storing the file locally on each system or compiling the connection string into the application and as long as your network is fairly quick the end users will not notice much of a difference. If it ends up taking time to retrieve the settings you can give the appearance of speed by using a splash screen that says that it is setting up the connections while you are retrieving the data.
0
 
LVL 1

Author Comment

by:cindyrod
ID: 18176427
Thanks for the info. I don't have time to try it now but I'll let you know as soon as I get some time.
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Welcome my friends to the second instalment and follow-up to our Minify and Concatenate Your Scripts and Stylesheets (http://www.experts-exchange.com/Programming/Languages/.NET/ASP.NET/A_4334-Minify-and-Concatenate-Your-Scripts-and-Stylesheets.html)…
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…
In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're interested in additional methods for monitoring bandwidt…

743 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