KavyaVS
asked on
Windows Application Connection String
I have Windows application with .Net 2.0
The connection string is hard coded in .exe of APP.Config file.I want to have some flexibility to change the connection string.
Is there any way to change the connection string and how to access it in .exe file.
Please give detailed idea of how to do this.
The connection string is hard coded in .exe of APP.Config file.I want to have some flexibility to change the connection string.
Is there any way to change the connection string and how to access it in .exe file.
Please give detailed idea of how to do this.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
example in VB.NET?
Can you post App.config file?
Can you post App.config file?
ASKER
This is what exactly I am looking for.If possible vb.net code otherwise C# is also fine.
I want to add external configuration file.Storing the connectionStrings section in a physically separate file is useful in situations where connection strings may be edited after the application is deployed.
How to do this. Any code examples is appreciated.
I want to add external configuration file.Storing the connectionStrings section in a physically separate file is useful in situations where connection strings may be edited after the application is deployed.
How to do this. Any code examples is appreciated.
Public Class DBHelper
Public Shared Property ConnectionString() As String
Get
Return My.MySettings.Default.MyCo nnectionSt ring
End Get
Set(ByVal value As String)
My.MySettings.Default.Prop ertyValues ("MyConnec tionString ").Propert yValue = value
My.MySettings.Default.Save ()
End Set
End Property
End Class
Public Shared Property ConnectionString() As String
Get
Return My.MySettings.Default.MyCo
End Get
Set(ByVal value As String)
My.MySettings.Default.Prop
My.MySettings.Default.Save
End Set
End Property
End Class
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
My.Settings.MyConString. What is My here.Is it Project name?
Thanks.
Thanks.
No. Its the My namespace of VB.NET which is available to every winforms app.
http://msdn.microsoft.com/en-us/vbasic/ms789188
http://msdn.microsoft.com/en-us/vbasic/ms789188
ASKER
CodeCruiser
You can set its value at design time as well as at runtime.
How to set it at runtime?
Thanks
You can set its value at design time as well as at runtime.
How to set it at runtime?
Thanks
My.Settings.SettingName = Value
ASKER
Hi CodeCruiser,
I want to set the connection string automatically after deployment.My idea is the .exe file able to read the external text file in the application directory.
Based on the server type if it is '1' pointing to Development server and if it is 2 pointing to Production server.How to do this?
How to change the connection string automatically after deployment without changing it manually.
Thanks
I want to set the connection string automatically after deployment.My idea is the .exe file able to read the external text file in the application directory.
Based on the server type if it is '1' pointing to Development server and if it is 2 pointing to Production server.How to do this?
How to change the connection string automatically after deployment without changing it manually.
Thanks
You can either keep two connection strings in the settings and use the one suitable. Or you can change the connection string before deployment.
You can have 3 settings: Server1String, Server2String, MyConString
Then on form load of main form, if its server type 1 then set MyConString = Server1String etc.
You can have 3 settings: Server1String, Server2String, MyConString
Then on form load of main form, if its server type 1 then set MyConString = Server1String etc.
ASKER
I don't want to change the form load of main form after deployment.
After deployment the executable able to know the server type from external file and uses the specific connection string.
Thanks
After deployment the executable able to know the server type from external file and uses the specific connection string.
Thanks
You dont change the form load after deployment. You change the connection string app will use in the form load.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER