?
Solved

Connection string for .NET Windows forms

Posted on 2006-11-27
8
Medium Priority
?
253 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
Get your Conversational Ransomware Defense e‑book

This e-book gives you an insight into the ransomware threat and reviews the fundamentals of top-notch ransomware preparedness and recovery. To help you protect yourself and your organization. The initial infection may be inevitable, so the best protection is to be fully prepared.

 
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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Recently while returning home from work my wife (another .NET developer) was murmuring something. On further poking she said that she has been assigned a task where she has to serialize and deserialize objects and she is afraid of serialization. Wha…
This article describes relatively difficult and non-obvious issues that are likely to arise when creating COM class in Visual Studio and deploying it by professional MSI-authoring tools. It is assumed that the reader is already familiar with the cla…
Sometimes it takes a new vantage point, apart from our everyday security practices, to truly see our Active Directory (AD) vulnerabilities. We get used to implementing the same techniques and checking the same areas for a breach. This pattern can re…
In response to a need for security and privacy, and to continue fostering an environment members can turn to for support, solutions, and education, Experts Exchange has created anonymous question capabilities. This new feature is available to our Pr…

649 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