I would like to have the possibility of specifying certain "properties" either during setup of my app or afterwards.
In my app I have a connection to my mysql server,currently localhost, but when I am going to install this the localhost will probably change to an IP address or hostname, is there any way that I can create like a properties box that asks the user what he/she wants the ip address or hostname to be to connect to,and then once they change it it should reflect in the code? Or maybe have an encrypted text file with all the settings in or a text file thats hidden with the settings in,not sure what the right approach will be, thank you for your answers and advise
You can store sensitive data in connection strings by encrypting them, see MSDN Documentation.
Related
I have a client application that connects to my server
I do not have access to the client's code anymore so how would I be able to change the string 192.168.2.12 into another string in order for me to be able to make it connect to my own server. In what way would I be able to do this in C# programmatically?
Thanks.
You can try to decompile the program and then search in the original source code how the value is set and adjust accordingly.
Sometimes the configuration strings are written in .exe.config
Just look at the client folder location to see if you have any files ending with .exe.config. There might be the string in it and you can change it there.
I've tried searching but had no luck as I'm not sure I'm using the correct terminology.
I'm trying to figure out how to ask a user to input their server name on the first application run, store that and insert it into filepath/connection string.
Pseudocode for initial run:
I see this is the first time you ran this application. Please input your fileserver name.
user inputs: fileserver123x
Write Fileserver123x to text file.
Initialize database connection
string fileServername = read text file;
connection = new OleDbConnection(#"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=\'"+fileServerName+#"'\share\folder\Database.accdb;Persist Security Info=False;");
rest of code
I'm looking to see if there is a better/more professional way to store the user file server information other than via text file and read it each time the DB connection is initialized.
Any thoughts?
Your concept looks fine, I'd suggest a few improvements:
Store the file server name in the Windows registry instead of a text file. This is where well-behaved Windows programs store their configuration data.
Store the complete path to the database instead of the file server name. That way, your customers don't have to use a fixed share/folder name.
Make a configuration window where this configuration data can be modified. This can also serve as the window you show on your first run.
Don't read the configuration data each time a connection is opened. Read it once when your application starts and store it in a global variable.
(Note: In general, global variables are a code smell, but storing global configuration data is usually considered a legitimate use case. If you want a more advanced solution that simplifies unit testing, look into dependency injection for your configuration data.)
I need to use a local pac file when the user is on a vpn.
The problem is that I do not understand how I will get the program to read it. From what I've read .net should be able to pick it up on start from the IE settings. The user can access the web using IE but my program does not work when on vpn, so I guess the pac file is not read. I have set the useDefaultWebProxy to true in that test.
When setting the wcf client proxy address to file:///path/file.pac I get an error that it cannot access it and when searching it can only access http:// so I guess this parameter is not going to work for me.
Any ideas on any workaround?
I am working on a web application which sits on a server and connects to various client machines based on the IPAddress.I have to change the IPAddress every time in the web.config file in order to connect to a particular client machine.
I want to put a text box where i can enter the ipaddress and it updates web.config file based on the button click which should eventually connect to the respective client machine.
Is it possible to do this way or i am thinking the wrong way ?
Can any one guide me in the right path ?
It sounds to me like your thinking is backwards.
If the application is dependent on you inputting an IP address every time, why store it in the web.config? Why not just build that into the application as part of the process to connect to the machine?
Run application page, request IP input, utilize input to connect to targeted machine.
The config file is meant for rarely changing settings and other application configuration data. This is a value that is needed on a per use basis, so request it on a per use basis.
If you have a set list of IP Addresses that you're always connecting to, you can store a delimited list in the web.config and then parse it. Something like:
<add key="IPAddressList" value="192.168.1.2;192.168.10.1;192.168.15.16" />
Then, in your application, just split and loop through the list:
foreach(string ip in ConfigurationManager.AppSettings["IPAddressList"].Split(';'))
//connect to server (ip = the IP Address)
If you're dependent on input each time, then it might just be easiest to save a List of IP Addresses to the Application.Cache and update that via your page (does it need to persist?).
I am coding a simple space empire management game in Visual C# 2008, which relies on connecting to a remote SQL server database to get/store data.
I would like the user to be able to connect to a user-specified SQL server from the login screen(he specifies IP address, port, database name, ID, password and presses "connect" button). However, I found out that the Dataset connection string property is read only and cannot be changed. Is there any way to guide the wizard-generated DataSet to a user-specified server at run time?
I believe that if you go into the project settings and change the connection string setting type from "Connection String" to "string" and change the scope from "Application" to "User", the connection still works and it becomes an editable string at runtime.
Please back up your source code before trying this.