473,386 Members | 1,786 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

Connection Strings C#

Hello,

I'm pretty new with this so please bare with me.

I have an ASP.NET application where all of the calls to the database are stored in a standalone C# file (DataStorage.cs). This file contains all the methods, AddCustomer, etc. and is really nice because I can call it from any of the pages in the application. The problem I'm having is with the connection string. Basically, right now the connection string is hard-coded and I would like it to be dynamic so I didn't need to worry about whether it was on my local machine, on the web server, or perhaps was moved to a different server. Anyways, I've used server.mappath in some of the regular application pages and it works fine but I can't use it in the DataStorage page because it's just a stand-alone C# file. Is there a way to get server.mappath in there? I assume I just need to import something, but I can't figure out what.

Thanks!
Apr 14 '07 #1
2 1363
gomzi
304 100+
Hello,

I'm pretty new with this so please bare with me.

I have an ASP.NET application where all of the calls to the database are stored in a standalone C# file (DataStorage.cs). This file contains all the methods, AddCustomer, etc. and is really nice because I can call it from any of the pages in the application. The problem I'm having is with the connection string. Basically, right now the connection string is hard-coded and I would like it to be dynamic so I didn't need to worry about whether it was on my local machine, on the web server, or perhaps was moved to a different server. Anyways, I've used server.mappath in some of the regular application pages and it works fine but I can't use it in the DataStorage page because it's just a stand-alone C# file. Is there a way to get server.mappath in there? I assume I just need to import something, but I can't figure out what.

Thanks!
add the connection string in the web.config and use it in c#.

WEB.CONFIG
<configuration>
<appSettings>
<add key="connectionstring" value="Server=yourservername;User Id=yourusername;Database=yourdb;password=yourpwd;"/>
</appSettings>
...


code behind..

Dim con As New MySqlConnection(ConfigurationManager.AppSettings(" connectionstring"))
Apr 14 '07 #2
Thanks, I'll give that a try.
Apr 14 '07 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

0
by: JWM | last post by:
I am trying to implement Oracle connection pooling for the following code, which was written by someone else. Here is my main question -- this java file creates code that is executed every hour,...
4
by: Matthew Wells | last post by:
FIRST OF ALL, I APPRECIATE PEOPLE SENDIUNG ME LINKS TO WEB SITES FOR CONNECTION STRINGS BUT AS I'VE SAID BEFORE THAT IS NOT WHAT I NEED. I CAN EASILY OPEN AN ADO CONNECTION OBJECT TO AS400. I...
1
by: stewart | last post by:
I've got the standard SqlCacheDependency working just fine , ie. I've defined (and encrypted) the connectionStrings section in the web.config, and I've also defined an an sqlCacheDependency in the...
7
by: Gary Brizard | last post by:
OK. For an n-tier architecture, where is the best place to store the connection string for the DA layer? I don't want to use the reg. Can't use a app.config for a dll. For other projects I...
14
by: WebMatrix | last post by:
Hello, I have developed a web application that connects to 2 different database servers. The connection strings with db username + password are stored in web.config file. After a code review,...
4
by: Matt Colegrove | last post by:
I'm working on a web app that is published to a hosting service. I'm developing it on my local PC with VS 2005 and SQL Express. The hosting service DB is SQL Server 2000. I have two...
5
by: Matt | last post by:
Hello, What is the best way to handle the database connection string for a class library project that will be compiled and used as a .dll? This .dll will be accessed via classic ASP and in...
3
by: Harry Strybos | last post by:
Hi All I have a really strange problem occurring in my application. When I read in the application settings for connection strings the following happens: Here are my connection string settings...
9
by: =?Utf-8?B?Vmlua2k=?= | last post by:
Hello Everyone, I have a question about storing the connection strings to the database in a config file or database. My manager wants me to store all the connection strings in a database, but I...
2
by: Johnson | last post by:
I'm trying to fix a "sub optimal" situation with respect to connection string management. Your thoughtful responses will be appreciated. I just started with a new client who has a bunch of legacy...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.