I want to use Entity Framework without app.config file.
I want to define a string variable Connection String in my code and use that to connect to the database.
Please show me the way if it is possible.
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
You’re not mentioning what approach you’re using (database-first, model-first, code-first) – but basically, in the end, you need to define a string variable and assign it a valid EF connection string
Example for database-first approach:
and then use that to create your
ObjectContext(database- and model-first) orDbContext(code-first)But quite honestly – I think this is a really bad idea since this makes it impossible for you to move your application to another machine – no one else can install and run this, since the connection string is hard-coded into your C# code….. the whole point of having config files is so that you can change / adapt things like connection strings so that they are not tied to a single machine/location but can be adapted to the particular needs of a given user / customer….