In the last few days, I finally learned how to connect my C # application (I am using Visual Studio 2010 Express) to my SQL Server 2008 R2 database using Entity Framework, and I am completely stuck.
When I want to add a new DataSource to VS, I just find the path to the db file, and when I finally find it and try to select it, it gives me an error message
This file is already in use. Enter a new name or close this file, which is used by another application
It sounds like nonsense to me because I haven't used the database file for two days. So, after a short search on Google, I finally found a solution, and I went into SQL Server Configuration Manager and restarted the only SQL Server.
Then my connection to the DataSource finally works , and I thought that now I am unsurpassed, and I will write my code until the end of days, but after a few minutes I had another problem: O (the reason I write here).
When I use any part of SQL Server in my VS application, my SQL Server stops working. I can’t browse the database there, I can’t change anything, I can’t use the query, just nothing. It just tells me that this database is already in use.
The same thing when I do it the other way around.
I restart SQL Server through SQL Server Configuration Manager (to be able to use SQL Server again), and then I, for example, use the database query task SELECT * FROM nameDatabase.
#, combobox, SQL Server , , SQL Server . ( , googling , , SQL Server ).
- , :
using (var entities = new PropertyDatabaseEntities())
{
var userNames = entities.Login
.Select(login => login.Username)
.ToArray();
comboboxLogin.Items.Clear();
comboboxLogin.Items.AddRange(userNames);
}
SQL Server , - SQL Server, .
, , , SQL Server, VS SQL Server.
.
*
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<configSections>
</configSections>
<connectionStrings><add name="Final.Properties.Settings.PropertyDatabaseConnectionString" connectionString="Data Source=.\SQLEXPRESS;AttachDbFilename="C:\Microsoft SQL Server\MSSQL10_50.SQLEXPRESS\MSSQL\DATA\PropertyDatabase.mdf";Integrated Security=True;Connect Timeout=30;User Instance=True" providerName="System.Data.SqlClient" /><add name="LoginEntities" connectionString="metadata=res://*/DataAccess.LoginModel.csdl|res://*/DataAccess.LoginModel.ssdl|res://*/DataAccess.LoginModel.msl;provider=System.Data.SqlClient;provider connection string='Data Source=.\SQLEXPRESS;AttachDbFilename="C:\Microsoft SQL Server\MSSQL10_50.SQLEXPRESS\MSSQL\DATA\Login.mdf";Integrated Security=True;Connect Timeout=30;User Instance=True;MultipleActiveResultSets=True'" providerName="System.Data.EntityClient" /><add name="PropertyEntities" connectionString="metadata=res://*/DataAccess.PropertyModel.csdl|res://*/DataAccess.PropertyModel.ssdl|res://*/DataAccess.PropertyModel.msl;provider=System.Data.SqlClient;provider connection string='Data Source=.\SQLEXPRESS;AttachDbFilename="C:\Microsoft SQL Server\MSSQL10_50.SQLEXPRESS\MSSQL\DATA\Property.mdf";Integrated Security=True;Connect Timeout=30;User Instance=True;MultipleActiveResultSets=True'" providerName="System.Data.EntityClient" /><add name="PropertyDatabaseEntities" connectionString="metadata=res://*/DataAccess.PropertyDatabaseModel.csdl|res://*/DataAccess.PropertyDatabaseModel.ssdl|res://*/DataAccess.PropertyDatabaseModel.msl;provider=System.Data.SqlClient;provider connection string='Data Source=.\SQLEXPRESS;AttachDbFilename="C:\Microsoft SQL Server\MSSQL10_50.SQLEXPRESS\MSSQL\DATA\PropertyDatabase.mdf";Integrated Security=True;Connect Timeout=30;User Instance=True;MultipleActiveResultSets=True'" providerName="System.Data.EntityClient" /></connectionStrings>
</configuration>