1

I am using C# WPF EF6.0 and SQL Server Express for final program.

I have created a setup file with Advanced installer that creates database via script and SQL Server Express in

C:\Program Files\Microsoft SQL Server\MSSQL11.SQLEXPRESS\MSSQL\DATA

and I have changed my string connection from

<add name="MyDBEntities" 
     connectionString="metadata=res://*/MyDBModel.csdl|res://*/MyDBModel.ssdl|res://*/MyDBModel.msl;provider=System.Data.SqlClient;provider connection string=&quot;data source=(LocalDB)\v11.0;attachdbfilename=|DataDirectory|\MyDB.mdf;integrated security=True;connect timeout=30;MultipleActiveResultSets=True;App=EntityFramework&quot;" 
     providerName="System.Data.EntityClient" />

To this

<add name="MyDBEntities" 
     connectionString="metadata=res://*/MyDBModel.csdl|
                       res://*/MyDBModel.ssdl|
                       res://*/MyDBModel.msl;
                       provider=System.Data.SqlClient;
                       provider connection string=&quot;
                             Data source=.\SQLExpress;
                             integrated security=True;
                             MultipleActiveResultSets=True;
                             Initial Catalog=MyDB;
                             App=EntityFramework&quot;" 
     providerName="System.Data.EntityClient" />  

I have installed .net Framework 4.5 and SQL Server 2012 sp1 v11.0.300 that I have used in Visual Studio 2013

When I install my program, everything works, but when I run my program it stopped working at first launch. I think the connection string has a problem. If I click debug in Visual Studio, I see this error

An unhandled exception of type 'System.InvalidOperationException' occurred in EntityFramework.dll.Additional information: No connection string named 'MyDBEntities' could be found in the application config file.

3
  • are you getting any error.. Commented Sep 5, 2016 at 13:32
  • No just stopped working Commented Sep 5, 2016 at 13:33
  • if i click debug in visual show this error.=>An unhandled exception of type 'System.InvalidOperationException' occurred in EntityFramework.dll.Additional information: No connection string named 'MyDBEntities' could be found in the application config file. Commented Sep 5, 2016 at 13:39

2 Answers 2

1

The reason is that you have not attached the database files to the local database engine. try to use the appropriate SQL Server methods which are available. Your application (after installation) can not find the database in the local DB engine.

Sign up to request clarification or add additional context in comments.

12 Comments

Actually you are using installation process so it seems that you want your application to be portable so you should not use absolute path. and about the mentioned attribute I guess you should take a look at connectionstrings.com/sql-server-2012
Have you included the database files to installer folders?
It is logical that is not working, go to your sql server detach the database, copy files in a separate folder with enough privilege then include the db data and log files in your installation folders.
Have they ever attached database in their installation?
|
1

Finally I couldn't create a setup file with Advanced Installer. But I created it by Install Shield. My problem was insert or delete or edit from database. I installed my program in other drive and my problem solved. The reason was a joke that program files in C is readonly.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.