Answer the question
In order to leave comments, you need to log in
What to fix in Entity Framework C# database connection string?
There is a database on SQL Server'e. There is an application that works with this database using this connection string:
<connectionStrings>
<add name="IPhoneDBContext" connectionString="metadata=res://*/Model.csdl|res://*/Model.ssdl|res://*/Model.msl;provider=System.Data.SqlClient;provider connection string="data source=DESKTOP-K4U1293;initial catalog=IPhoneDB;integrated security=True;MultipleActiveResultSets=True;App=EntityFramework"" providerName="System.Data.EntityClient" />
</connectionStrings>
<entityFramework>
<defaultConnectionFactory type="System.Data.Entity.Infrastructure.SqlConnectionFactory, EntityFramework" />
<providers>
<provider invariantName="System.Data.SqlClient" type="System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer" />
</providers>
</entityFramework>
Answer the question
In order to leave comments, you need to log in
In order to transfer the database, you need to choose what to use first:
1) Sql Server CE (Compact Edition) - a stripped-down engine that you can carry with you as a library. But he has been deprecated since the age of 13.
2) Sql Server LocalDB. But it needs to be installed separately on each machine. It used to come with VisualStudio, I don't know now.
3) sqlite, which will work everywhere, but it has its drawbacks.
4) Use a regular Sql Server instance (maybe Express, it doesn't matter), and carry only the database with you.
Depending on what you choose, the connection string will change. Now you have it for a regular Sql Server instance:
data source=DESKTOP-K4U1293;initial catalog=IPhoneDB;integrated security=True;MultipleActiveResultSets=True;App=EntityFramework
. Server=DESKTOP-K4U1293;AttachDbFilename=|DataDirectory|mydbfile.mdf;Database=IPhoneDB;
Trusted_Connection=Yes;
. Server=(localdb)\v11.0;Integrated Security=true;
AttachDbFileName=|DataDirectory|mydbfile.mdf;
So I wrote a screenshot for you. What else do you want? According to the screenshot, your models are explicitly described by the CodeFirst approach, and the shown connection string has links to class mapping models - entities in the database (DatabaseFirst). There is either a cross or shorts. As far as I remember the CodeFirst approach - the connection string should contain only the location of the database server and details sufficient to manipulate both data and table structures. Regarding the transfer, I didn’t understand and didn’t see the problem at all, these are already some of your fantasies. The application contains a config, it contains the connection strings with the database. What else do you want? Yes, when deploying a project - in the resulting distribution, or whatever you put there, there will be a config containing a connection string
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question