?
Solved

Connection string for .NET Windows forms

Posted on 2006-11-27
8
Medium Priority
?
251 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Free learning courses: Active Directory Deep Dive

Get a firm grasp on your IT environment when you learn Active Directory best practices with Veeam! Watch all, or choose any amount, of this three-part webinar series to improve your skills. From the basics to virtualization and backup, we got you covered.

 
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 2000 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

Microsoft Certification Exam 74-409

Veeam® is happy to provide the Microsoft community with a study guide prepared by MVP and MCT, Orin Thomas. This guide will take you through each of the exam objectives, helping you to prepare for and pass the examination.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

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)…
This document covers how to connect to SQL Server and browse its contents.  It is meant for those new to Visual Studio and/or working with Microsoft SQL Server.  It is not a guide to building SQL Server database connections in your code.  This is mo…
Michael from AdRem Software outlines event notifications and Automatic Corrective Actions in network monitoring. Automatic Corrective Actions are scripts, which can automatically run upon discovery of a certain undesirable condition in your network.…
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…
Suggested Courses

765 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