简体   繁体   中英

VB.Net Should I Store Database Connection String with Application or User Scope?

All of the examples I've seen set the connection string in app.config at the application level, but application settings are read-only. However, I want to allow the user to update the connection string at run time as a user preference. I've found a workaround to update the connection string as an application-level setting, but there are probably reasons why it's read-only and I feel like I'm implementing a bad practice. Should I set this setting at the user level instead?

Could you simply add the variations as separate connectionstring and present the user with a combo to choose from?

If you really need to build everything dinamically then take a look at SqlConnectionBuilder class

This example is the same one presented in the link above

Dim builder As New System.Data.SqlClient.SqlConnectionStringBuilder
builder("Data Source") = "(local)"
builder("Integrated Security") = True
builder("Initial Catalog") = "AdventureWorks"
Console.WriteLine(builder.ConnectionString)

You kind of have a little problem. If you want all users to have the same list of connection strings, then you need a storage common to all which is usualy the database.

If you want to store it per user, then Isolated Storage , local .xml config or the My.Settings .

If you want all user to have the same list, then you might want to think of a web service. Or you could have a "main" connection string, that never changes that will contain the list of the other connection strings.

Sometime, you'll see the .msi (the setup) ask for the connection string. You grab it and save it at installation.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM