Managing windows application's DB connection
There's no particular problem, I just wanted to ask whther I'm doing it right or wrong.
I have connection string stored in Settings.Default.ServerConnection
property on which rely all DB-related objects. I also use auto-generated TableAdapters for server-side stored procedures (SQL Server 2008 R2 Express) with Connection property set to use mentioned connection property. There is a settings form where I can setup a connection to any server on the local network (using SqlClientFactory.Instance.CreateDataSourceEnumerator().GetDataSources()
) and store it in app's settings.
So I was wonderi开发者_运维技巧ng if it's the right approach of doing such thing or not because when app is executed for the first time it's still able to connect to SQL server without even configuring the connection (Data Source
set to (local)
by default).
If I'm understanding the question... :-)
Your app is able to connect to local because that is the how its bound in its current environment (say it was a remote IP, it wouldn't work).
Storing connection string information in the config file (e.g. app.config) is a great idea, because it can be changed on the fly without a rebuild.
精彩评论