.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
Sign In
Win Surprise Gifts!!!

Top 5 Contributors of the Month
Gaurav Pal
Post New Web Links

EF 4.1 connection string code first and object context

Posted By:      Posted Date: April 14, 2011    Points: 0   Category :ASP.Net

I have a question about using  an existing sql express(from a web host) with entity framework 4.1) and using an existing database  

Does this map directly using the following method. I posted this question in the msdn site and I really did not get a very good response so I hope someone helps out. my question Is what is the best way to map to an existing database on a web host    

  http://blogs.msdn.com/b/adonet/archive/2010/12/06/ef-feature-ctp5-code-first-walkthrough.aspx here is using a sql  default constructor

http://msdn.microsoft.com/en-us/library/bb896291.aspx you have to pre-configure entity framework here ....

I was wondering is this the way you do it using objectcontext

Public class  Blog context: Db context

public Blogcontext (Db connection connection)


View Complete Post

More Related Resource Links

Writing connection string in web.config file by code or dynamically

I want to write connection string in web.config file of my application by code. If anyone know the way or code just help me..NET,C#,SQL SERVER

SQL Connection String

We can learn or know how can we connect the database from our .net. This will help for freshers or .NET beginners!

abstract away the source of the connection string using a class with a static property.

ASP.NET provides a configuration system we can use to keep our applications flexible at runtime. In this article we will examine some tips and best practices for using the configuration system for the best results.

The element of a web.config file is a place to store connection strings, server names, file paths, and other miscellaneous settings needed by an application to perform work. The items inside appSettings are items that need to be configurable depending upon the environment, for instance, any database connection strings will change as you move your application from a testing and staging server into production.

Let's abstract away the source of the connection string using a class with a static property.

connection string question from a newbie


when publishing  in the webmatrix dialogue it asks for "destination connection string" for my "database.mdf"

I was not sure what it was so I pasted this from my web.config file :

Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\database.mdf;Integrated Security=True;User Instance=True

it all published ok, but wont run, so I guess it has somthing to do with this connection string or some kind of configuration issue.

My question is this, What should go in the field for "Destination connection string"

Modifying connection String in Web config using Install Wizard



Im trying to create a Web Deployment Project, the built in setup and deployment is very good in Visual Studio, i need to able to add an additional step in the setup to change the connection string in the Web config file. Ive seen a lot of articles on how to do this and in particular this http://weblogs.asp.net/scottgu/archive/2007/06/15/tip-trick-creating-packaged-asp-net-setup-programs-with-vs-2005.aspx#7162670 I am however stuck on the final part of this tutorial, im using the code Scott provided but have two errors,  heres part of my code where the errors are

using System;
using System.Configuration;
using System.Configuration.Install;
using System.ComponentModel;
using System.Diagnostics;
using System.IO;
using System.DirectoryServices;

 void ConfigureDatabase(string targetSite, string targetVDir, string connectionString)
            // Retrieve "Friendly Site Name" from IIS for TargetSite
            DirectoryEntry entry = new DirectoryEntry("IIS://LocalHost/" + targetSit

Protect It: Safeguard Database Connection Strings and Other Sensitive Settings in Your Code


Protecting application secrets, such as database connection strings and passwords, requires careful consideration of a number of pertinent factors such as how sensitive the data is, who could gain access to it, how to balance security, performance, and maintainability, and so forth. This article explains the fundamentals of data protection and compares a variety of techniques that can be used to protect application settings. The author discusses what to avoid, such as hiding keys in source code and the use of Local Security Authority. In addition, he presents some effective solutions such as the Data Protection API.

Alek Davis

MSDN Magazine November 2003

Can't Load 32-bit Com Object into managed code (C#) in runtime with 64-bit Enviroment

Hey everyoneI need your help with some 64-bit issues. I recently had to migrate my work to a 64-bit enviroment.  I'm using VS 2005.I have a simple c# application that is using an unmanaged c++ Com object. both are 32-bit applicationsBoth projects compile smoothly, and when i register my com object it succeeds. However, during runtime when i try to create an instance of the com class: 'someComClass a = new someComClass()' I get the error:COMException : Retrieving the COM class factory for component with CLSID {XXXXXXXXX} failed due to the following error: 80040154OK people, bring it on, what's wrong ? how do i fix it ? registery issues ? compiler issues ?Any help is welcomedWith thanksOded

Context Connection problem in SQLCLR

I am using context connection in the sqlclr (and there are reasons to do so). While a datareader is under execution that uses the context connection, I need another database read passing one of values being read from the datareader. Since I cann't use the context connection for this second read (as context connection is already in use), how can I create a second connection to be used with this second read. I cannot create the hardcoded connections string for the second connection as the database is dynamically selected. The database is same as used by the context connection. I can use the server=localhost though, but cannot hardcode the database name as the database can be different in different sqlclr proc call. However the database is same as used by the context connection. (If I somehow get the database name from the context connection then I can use it to create another connection, but I am expecting an even better solution)   Any solution to this problem? Will be very thankful.

Custom security via connection string

Hi Is it possible to pass information into the SQL Server relational engine via the connection string in the same way as it can be done for Analysis Services? I need to generate a user context for a forms authentication application (i.e. no windows user accounts). SSAS allows you to pass in a list of database roles or a customdata parameter on the connection string. These can be used inside the database in lieu of a windows identity. I am wondering if there are equivalent parameters available for the SQL connection string.  I guess that I could create SQL logins from each of the forms users with a system generated password and then pass the uid and password on the connection string but this seems unnecessarily complicated. Andrew Wiles - www.it-workplace.com - MDX made simple

connection string

on the computer with sql management installed i use this and it works(server name):  .\SQLEXPRESS the computer name is: MAINCOMPUTER2 another computer on the network would use what? i can see  the c drives on either computer from either computer so i am connected.    

Connection string

Hi There!I am doing a project using Visual Web Developer Express. I have built a database using MS SQL Server Express which I have installed together with Visual Web Developer Express. Please help me what sort of the connection string I should use in the pages of my website to establish connection to the database.Thank you

problem in connection string

i have problem in connection strin i host my siteand database is in DATA DIRECTORYmy site run successfully in offline but an error of connection string in online pls give me an example of string for onlinei use asp.net, C# and sqlserver 2005

Best way to Deploy InfoPath form with connection information and managed code

Hi, Whats the best way to deploy an InfoPath form with connection information and managed code. Is there way I can create a deployment package for this? Thanks in advance, San

How to change connection string of a pivot table pointing to SSAS 2005 cube using excel 2003?

Hi All,I am not sure if I should have posted this query to Excel 2003 forum. But posting it here as it applies to SSAS 2005 as well.Ok, let me give the background before I tell the actual problem.We have users on ABC domain and the SSAS server is also on ABC domain. Users on this domain can acess the excel pivots by connecting to cube to browse the data. They leave the Userid & password field blank while they setup the connection string and it works fine. Thanks to windows authentication that takes the credentials of user logged in. Let's say I have two users A and B, they login to ABC domain with their own windows ids.  Now when user A creates a excel file having a cube pivot and then sends this file to user B, user B can refresh and modify the same excel file (he can select new measures to pivot, new hierarchies in filters and so on).Now, let's say I have another user, user C. He has excel 2003 installed on his PC and cannot migrate to excel 2007. He is on different domain XYZ but have a valid windows userid on domain ABC. The domain ABC & XYZ can not be setup to have trusted relationship. Now, when user A sends the same excel file to user C. When user C opens the file and try to refresh it or try to modify the pivot by selecting/deselecting any elements, he gets below error prompt:" An error was encountered in the transport layer." and "Errors in the
ASP.NetWindows Application  .NET Framework  C#  VB.Net  ADO.Net  
Sql Server  SharePoint  Silverlight  Others  All   

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend