Unable to run my app again after opening my database with the Server Explorer - entity-framework

I successfully use EF4 to build my database from scratch. My database is an SQL EXPRESS database file. I can manage this one with Sql Server Management Studio. So far so good.
I noticed that if I open my database with the Server Explorer in Visual Studio, the next time I run the application I got errors.
I also noticed that a new log file has been created. So now I have 2 log files.
Below is my connectionstring:
<add name="DocumentManagerEntities"
connectionString="data source=.\SQLEXPRESS2008;Initial Catalog=DocumentManagerDB;AttachDBFilename=|DataDirectory|DocumentManagerDB.mdf;Integrated Security=SSPI;MultipleActiveResultSets=True"
providerName="System.Data.SqlClient" />
What's wrong?
Thank you very much.

That maybe because multiple applications are trying to use your database at once. You need to close one connection to open another.
This article notes that
SQL Server Express Edition allows only a single connection to an .mdf
file when you connect with a connection string that has User Instance
set to true.
Further more
When you connect to a local database project, Visual Web Developer
connects to the SQL Server Express Edition database with user
instances enabled, by default. For example, the following code example
shows a typical connection string used by Visual Web Developer to
connect to a SQL Server Express Edition database.

Related

Entity Framework - I want the database to be created on a different SQL Server

My EF tutorial project works fine on a machine with SQL Server installed, but when I move the project to a machine with no SQL Server installed, the code below fails:
Database.SetInitializer(new DropCreateDatabaseAlways<EmployeeDb>());
I'd like to get the project working on a machine which has only the SQL Server client not the server. I've experimented with connection strings in app.config without success. Help much appreciated.
you have install SQL server in separate machine and configure to connect from other systems and put that machine name(or IP address) in connection string.
Configure the Windows Firewall to Allow SQL Server Access
how-to-enable-remote-connections-in-sql-server-2008

Windows Azure - Mobile services, database connection

I'm having trouble running sql commands to my database on Windows Azure. Previously I had no problems at all running my commands and stored procedures with SQL management studio until I added another database on the same server. I can still connect and even se all the tables and both databases i SQL management studio but I cannot run any commands.
If I use the online management portal I am able to run my SQL but not with SQL management studio.
select * from nextlabel.[Article]
and it gives the folowing error:
Invalid object name 'nextlabel.Article'.
Any ideas on how to connect properly to one of the databases or if I'm doing something else wrong?

How to connect a Windows forms application to a SQL Server database through a lan network?

I have written a Windows forms application in vb.Net (Visual Studio 2010) and my form is completely connected to a SQL Server 2008 database. All things are true when using my program in my machine but when I try to run it by other systems in the network the following error occur:
A network -related or instance -specific error occurred while establishing a connection to SQL
server. the server was not found or was not accessible......
I have installed framework.net3.5 and Microsoft SQL Native Client
But do not any special settings .
Please help me I need some basic helps because its my first time to do some things like this.
thanks
Connection string is:
<add name="Mosalasbandi.My.MySettings.Contorol_FaniConnectionString"
connectionString="Data Source=Ehsan-PC;Initial Catalog="Contorol Fani";Integrated Security=True"
providerName="System.Data.SqlClient" />
connection string as follows
String connstr=#"Data Source=tcp:196.211.164.122\ABC\SUTSVR,1433;Initial Catalog=pubs;User ID=sa;Password=OOPS";
note:
196.211.164.122 remote machine and 1433 port number
ABC is name of the server/workstation that your sql instance live.
SUTSVR is name of the sql instance
in addition to above make it sure that the your Sql instance configure to access remote computer.
good luck!!!!

aspnetdb.mdf and Microsoft.ACE.OLEDB.12.0

I'm trying to run my asp.net application on a windows machine (XP SP3, Vista, 7) which has only Microsoft.ACE.OLEDB.12.0 as the database engine installed and need to connect to the standard aspnetdb.mdf user database.
Does any one know it is possible to use a connection string that works with mdf files in such a condition? I used connection strings like this but no success yet:
connectionString = "provider=Microsoft.ACE.OLEDB.12.0;Data Source=.\SQLEXPRESS;Integrated Security=SSPI;AttachDBFilename=|DataDirectory|aspnetdb.mdf;User Instance=true";
Thanks
Try one like this:
Provider=Microsoft.ACE.OLEDB.12.0;Data Source=|DataDirectory|\aspnetdb.accdb;Persist Security Info=False;
For more connectionstrings, go to http://www.connectionstrings.com/access-2007
EDIT: It's not possible to connect to a Sql Server database using OleDB. Install SQL Server (Express) instead.

Sharing a SQLExpress database between EF and SqlRoleProvider

I have a database in SQLExpress 2008 that I am accessing via an EF4 connection. It also contains the ASP.Net role provider tables for the website. In the web.config there are two separate connection strings pointing to the same database. When it comes to debugging the database I get the following error:
Unable to open the physical file
"D:\TFS\Main\Source\TestWeb\TestWeb\App_Data\TestDB.mdf".
Operating system error 32: "32(failed
to retrieve text for this error.
Reason: 15105)". An attempt to attach
an auto-named database for file
D:\TFS\Main\Source\TestWeb\TestWeb\App_Data\TestDB.mdf
failed. A database with the same name
exists, or specified file cannot be
opened, or it is located on UNC share.
What I assume this means is that the two different connection strings cannot both attach to the SQLExpress database at the same time?
Here are the connection strings:
<add name="SqlRoleManagerConnection"
connectionString="data source=.\SQLEXPRESS;
Integrated Security=true;AttachDBFilename=|DataDirectory|TestDB.mdf;
User Instance=false;MultipleActiveResultSets=True"/>
<add name="TestDBEntities"
connectionString="metadata=res://*/TestDB.csdl|res://*/TestDB.ssdl|res://*/TestDB.msl;
provider=System.Data.SqlClient;
provider connection string="Data Source=.\SQLEXPRESS;
AttachDbFilename=|DataDirectory|\TestDB.mdf;
Integrated Security=True;User Instance=false;
MultipleActiveResultSets=True"" providerName="System.Data.EntityClient" />
Missing open angle bracket on each connection string is deliberate here and is because of a limitation of SO.
Any ideas how I can get around this?
I have the same situation: EF and Role provider connected to the same database and two connection strings as well. But I don't have "AttachDBFilename..." in my ConnectionStrings but instead in the RoleManager ConnectionString Database=MyDb and in the EF ConnectionString Initial Catalog=MyDb. In SQL Server Management Studio I have attached my physical Db to the object explorer and named MyDb. This works. Don't ask me why. Regarding connection strings I am on the level of "let the wizards do the stuff". They have created the strings this way.