Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
How to configure for SQLstringconnect on client machine
Message
From
21/02/2005 17:58:20
 
 
General information
Forum:
ASP.NET
Category:
Deployments
Environment versions
Environment:
VB.NET 1.1
OS:
Windows XP SP2
Network:
Windows XP
Database:
MS SQL Server
Miscellaneous
Thread ID:
00988971
Message ID:
00989055
Views:
38
This message has been marked as the solution to the initial question of the thread.
Glenn,

I didn't realize that you were talking about an ASP.NET app, but it doesn't make any difference. I already showed you what the web.config file should look like. All you need is to have a method to get that ConnectionString. Something like this would work:
public SqlConnection GetConnection()
{
	string cConnection = ConfigurationSettings.AppSettings["ConnectionString"];
	if (cConnection == null)
	{
		cConnection = "server=(local);database=localdatabase;uid=sa;pwd=";
	}
	SqlConnection conn = new SqlConnection(cConnection);
	return conn;
}
Note that I have a default connection string set to get a local database if it doesn't find the ConnectionString in the config file. You don't have to do this the same way, you could produce an error or something instead, it's up to you. Again, as I mentioned in my previous post, this is not very secure as the password is in plain view. If you used trusted connection instead of username/password, then I guess it wouldn't matter.

~~Bonnie



>Thanks Bonnie,
>
>I am just beginning to make the VFP to .NET mind bend, and have written a VERY small ASP.NET test app and had no idea how to install the new app on my production machine. Currently the connection string is "hard coded" in the SqlConnection component.
>
>Please excuse me for asking stupid questions, but could you demonstrate how I can "soft code" my SqlConnection?
>
>Thanks a million
>
>Glenn
>
>>Glenn,
>>
>>And how are you currently doing it?
>>
>>You can use a config file and put the connectionstring in there:
>>
>><?xml version="1.0" standalone="yes"?>
>><configuration>
>>  <appSettings>
>>    <add key="ConnectionString" value="server=MyServer;database=MyDataBase;uid=UserName;pwd=MyPassword" />
>>  </appSettings>
>></configuration>
>>
>>Not real secure, as the password is in plain view, but I'll let you figure out how to deal with that. <g> If this is on the client machine, then the config file would be called MyApp.exe.config and would reside with the EXE. We connect to our database via Web Services, and so in that case the config file is on the Web Server and is called web.config.
>>
>>~~Bonnie
>>
>>
>>
>>>When deploying a .Net app which used a SQL backend, how do you program the connect string to be both compatible on your dev machine and on the user's machine? Can I use a configuratrion file (INI) or a Reg setting? If so are there any good examples?
>>>
>>>Thanks
>>>
>>>Glenn
Bonnie Berent DeWitt
NET/C# MVP since 2003

http://geek-goddess-bonnie.blogspot.com
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform