Web Config - Where Should Connection Strings Be Stored In A N-tier Application
Sep 29, 2010
I have an ASP.NET project which is pretty n-tier, by namespace, but I need to separate into three projects: Data Layer, Middle Tier and Front End.
I am doing this because...
A) It seems the right thing to do, and
B) I am having all sorts of problems running unit tests for ASP.NET hosted assemblies.
Anyway, my question is, where do you keep your config info?
Right now, for example, my middle tier classes (which uses Linq to SQL) automatically pull their connection string information from the web.config when instantiating a new data context.
If my data layer is in another project can/should it be using the web.config for configuration info?
If so, how will a unit test, (typically in a separate assembly) provide soch configuration info?
I have heard that saving connection strings and stored procedure names in web.config file of our application is not safe. It is a good practice to store the connection string in a config file rather than as a hard coded string in our code and if we need to change it,then it makes our job easier. how to protect our code in web.config?
I have an ASP.NET project which is pretty n-tier, by namespace, but I need to separate into three projects: Data Layer, Middle Tier and Front End.I am doing this because...
A) It seems the right thing to do, and
B) I am having all sorts of problems running unit tests for ASP.NET hosted assemblies.
Anyway, my question is, where do you keep your config info?Right now, for example, my middle tier classes (which uses Linq to SQL) automatically pull their connection string information from the web.config when instantiating a new data context.If my data layer is in another project can/should it be using the web.config for configuration info?If so, how will a unit test, (typically in a separate assembly) provide soch configuration info?
How Can We Have two Connection Strings In Web.Config And Switch Betweeen Them In Code Behind? when i add two connention strings in web.config so an error appears that tells us u cann't add two connection strings in web.config. i want the upper job because i have 2 databases and i want transfer data from another to the other one.
I have two connection strings (both in Web.Config: CS_Local and CS_Production) for my DBML (Linq to SQL). In my Global.Asax/Application_Start I run some production preparation methods if the request is non-local (!HttpContext.Current.Request.IsLocal). Within that part, I'd also like to change the current connection string used by my DBML from the standard CS_Local to CS_Production.
I want to apply some better security measures to an existing web application. Currently, my connection string contains the user name and password in plain text. I'm also using a custom membership provider, which stores user names and passwords in the web.config file as plain text [URL] I would like to secure this information using an algorithm such as SHA1.
I have seen the examples on how to switch between connections strings for development and production enviroments. My web.config also calls out a connection string for <roleManager and membership><providers>. Can this be setup to switch between the two connection strings?
I would like to use both of the connection strings in the same web.config file how can I do this I tried this yesterday it worked I called it a night, then this morning I got this. The error being on line: 10 Parser Error Message: The entry 'ApplicationServices' has already been added.
Line 8: <add name="ApplicationServices" Line 9: connectionString="Data Source=Mysource;Initial Catalog=travelatlantic;User ID=MyID; Password=MyPassword;" /> Line 10: <add name="ApplicationServices" Line 11: connectionString="Data Source=MySource;Initial Catalog=travelatlantic2;User ID=Myid; Password=MyPassword;" /> Line 12: </connectionStrings>
i want define connectionSreing in the web.config and then use it for DataContext ConnectionString. i do that : 1. i creat a class in App_Code :(MisaghDB is my database)
partial class MisaghDataContext { partial void OnCreated() { this.Connection.ConnectionString = ConfigurationManager.ConnectionStrings["MisaghDBConnectionString"].ConnectionString; } // or public partial class MisaghDataContext { public MisaghDataContext() : base (ConfigurationManager.ConnectionStrings["MisaghDBConnectionString"].ConnectionString) { OnCreated(); } } }
2. Add the connection string to my web.config file:
3. Right click on the DBML file design surface and chose properties. Select "none" for the Connection property.now should i change DBML file designer.cs (Misagh.designer.cs) ? The code should I delete in this file(DBMLfile designer.cs)? this is a part of my DBMLfile designer.cs :
[global::System.Data.Linq.Mapping.DatabaseAttribute(Name="MisaghDB")] public partial class MisaghDataContext : System.Data.Linq.DataContext { private static System.Data.Linq.Mapping.MappingSource mappingSource = new AttributeMappingSource(); public NorthwindDataContext() : base(global::WindowsFormsApplication2.Properties.Settings.Default.NorthwindConnectionString, mappingSource) { OnCreated(); } public NorthwindDataContext(string connection) : base(connection, mappingSource) { OnCreated(); } public NorthwindDataContext(System.Data.IDbConnection connection) : base(connection, mappingSource) { OnCreated(); } public NorthwindDataContext(string connection, System.Data.Linq.Mapping.MappingSource mappingSource) : base(connection, mappingSource) { OnCreated(); } public NorthwindDataContext(System.Data.IDbConnection connection, System.Data.Linq.Mapping.MappingSource mappingSource) : base(connection, mappingSource) { OnCreated(); } ............}
I have a C# web service where I need to access a MS SQL DB. I see a way of creating a connection string in IIS and using it in the web application when connecting to the DB. In IIS in Connection strings you specify the name of the connection, server, user n pwd How can I use the name of connection string created in IIS in my c# app.? I am currently using
CustomerInfo customerinfo = new CustomerInfo(); // to return using (SqlConnection connection = new SqlConnection("server=servername; initial Catalog=eostartest; Integrated Security=SSPI")) {...
But I would like to use the name of the connection string created in IIS Connection Strings manager. Do I have to add something in the web.config as well?
How to run asp.net application with encrypted web.config ,is it possible note that ASP.NET application have a database with encrypted connectionstring and a "cannot read connection string " message is generated
What is the most correct way to save your connection string when using the n-tier approach ? Right now I have two windows app and one web app using my DLL library, what I'm currently doing is to create a static method inside my dal "GLOBALDAL" inside I'm making this check:
Code: if (System.Web.HttpContext.Current != null) ... if httpContext.Current is null That's mean that one of my windows applications doing the request, if so I get the CN from a file otherwise it's mean its the website knocking on my door so I get the CN from: Code: System.Web.HttpContext.Current.Application["ConnectionString"] I am thinking of changing it all and just set properly in my DA layer that expose the CN as a string. But I fear of security issues. So what is the correct way?
In IIS 7 you can create database connection strings. I suppose this must be encrypted and best protected by IIS. This is nice, but how do I access it programmatically?
I used the following command to encrypt my connection string but an error ocurred, "The connection name'DatabaseConnectionString1' was not found in the applications configuration or the connection string is empty" How can I encrypt it while keeping the application working? What if I move the encrypted application to another computer? Will it work?
just for my testing purpose i know i can define both the connection's outside in a single web config file by different name's and access them in my front end according to it but what if i want to have seprate for both connection's web.config situation is like this see image so i want to access my connections from second web config file how i can do that.
I was asked to design a asp.net website with modular programming, yet I have no clue what that actually means, does he mean structured programming?, everything I've found on modular programming has no relation to an asp.net website (or its code behind). Could someone explain what it means if: I have a database connection on each page of the website rather than having the connection string in the global or webconfig page? Does this mean structured or modular? In what terms could you achieve modular programming with a website that has no loadable modules? Its just a site with a few connection strings and some clever programming to do some fancy html?
I've seen other posts about webparts and cms but really have no understanding of them? Are they relevant? Unsure. My site is just a social network site that allows some one to login/create account with the website then go to his own profile and display things about himself that are saved to our database. Nothing in it requires modules as far as I can tell? So it makes me think is it a different method of actually "programming" writing the code? i.e is it stored in a different manner is it refrenced in a different manner is called in a different manner?
I'm using the template posted in this thread to generate C# enums from a couple of lookup tables in SQL Server within a class library that contains my DAL.
At the moment, I have the connection string used by the templates embedded an a template include file in the class library. Is there a convenient way to have the template grab the connection string from the main project (WAP)'s web.config without having to include a physical path? Or is there a better way to approach this?
I've also considered creating a SQL CLR assembly which returns a table-valued function containing the enum contents (which would then be defined in C#, not in the database), but I'm not sure what the performance hit would be. Whether or not it's significant will obviously be application-dependent but I'd hate to charge down a crappy path if it's a know best-avoid-this approach.
On most of my asp.net web application I have at least 4 computers that I am constantly moving my application around to. My development PC at work, at home, a test web server for others to test then finally the production server. In all cases I am using a MS-SQL database that would be on a minimum of 3 (usually 4) different sql servers. I am constantly changing the connection string(s) in the web.config file. Now I have just learned about Entity Frameworks which apparently requires its own connection string.
As far as I know the only references to the connection string(s) would be the web.config settings for the asp.net membership and role provider settings and now the entity framework object. So I was hoping I could do some coding in the Global.asax unit under some function and "detect" which server I am running on maybe by its name or something that would be both constant and unique on all machines. Then programmatically configure the membership provoders and entity framework object to use the correct connection string.
This seems like a really silly question, but I've had a search around and I can't find anything about this. I've got a DB connection string that I'm creating in my web.config:-
[Code]....
and
[Code]....
but I need this connection to be read only. I've defined all my linq objects with only gets on their properties, and none of my (MVC) repository classes have .SubmitChanges() methods in them so I'm 99% sure the system can't update this DB, but I would also like to set my DB connection to be RO if at all possible. I realise that ideally this should be done at the SQL server end and the user should be made RO, but that (for various reasons, out of my control) can't be done, so I wanted to lock down my connection as the app mustn't write to the DB.
Is there a "readonly" parameter I can apply to the connection string so that it would throw an error or discard the data if any updates were attempted?