I have an windows desktop application which uses Mssql2005 express database.
But sometimes, my application cannot connect with the database.
When I run "exec sp_helpdb", my database name is not included in the result list. And when I try to attach my database, server says "database name already exist".
What happened with my database, please help me on this issue!
My application built on .NetFrameWork3.5
Kind Regards
Are you open a connection to the database in your application and you are not closing it?
Try to check the number of your connection with this script, before you are running your app, in the middle and after it got stuck-
SELECT
DB_NAME(dbid) as DBName,
COUNT(dbid) as NumberOfConnections,
loginame as LoginName
FROM
sys.sysprocesses
WHERE
dbid > 0
GROUP BY
dbid, loginame
source
Related
I know there are similar questions, but I have a specific problem.
Microsoft Visual Studio (2017) pops up this error when I try to create a DB connection for my Entity Data Model
The attempt to attach to the database failed with the following
information: Login failed for user 'sa'.
What I've already checked:
1) The sa user's password hasn't expired or isn't different than what I have specified.
2) The sa user has not been disabled, either by being denied permission to connect to the database engine nor having the login disabled.
3) My instance of SQL Server 2016 (Developer Edition) is configured for SQL authentication.
4) SQL Server is running and I also can connect to it by SQL Server Management Studio (v17.1) via sa and Windows Authentication as well.
What the problem could be?
UPDATE:
I tried to create a DB connection, when adding ADO.NET Entity Data Model -> EF Designer from database -> New Connection -> Microsoft SQL Server Database File (the SchoolDB.mdf wasn't attached to SQL Server... maybe this is the source of the problem)
To be honest, I tried to carry out the same action (make a connection to database (SchoolDB.mdf) and attach the SchoolDB.mdf file to SQL Server), and then Visual Studio gave me a hint:
The database file that you are attempting to connect is not compatible
with the current instance of SQL Server.
Then VS suggested me to upgrade the database file (SchoolDB.mdf).
After I'd done an upgrade of the *.mdf file (that I was trying to attach to SQL Server and make a connection to this DB after that), I could establish a connection to this database (already attached to SQL Server).
Screenshot
PS: I found out that SchoolDB.mdf was created by SQL Server 2012, while I tried to connect it to SQL Server 2016.
I'm using Umbraco CMS v7.4 with SQL Server 2014, the project was working fine until a few hours ago, when an error started showing up:
Umbraco cannot start. A connection string is configured but the Umbraco cannot connect to the database
The error occurs when I tried to open the website, see the image below:
I tried the following:
Checked to see if SQL Server is running
Checked the connection string credentials in web.config
Any help is appreciated.
After a few tries, even I loaded the backed up DB, I found that it caused by the DB login, the user in the connection string was having a password expiration enabled (the password had expired).
So, this is what I did:
Open the SQL server
Logged in as the user used in the connection string
Created a new password
Updated the web.config connection string "Password"
Hope this will help
So, in my case I tried to get started with the existing project. I got all the files, restored DB backup locally, made sure all permissions are set for IIS AppPool user etc. But I kept getting the error in question. It turns out that I cannot use server=localhost;database=... in connection string. After I replaced it with server=.\;database=..., it started to work right away.
Also note that if you're running it in Azure with an Azure SQL database you'll have to go to the Azure SQL Server settings and under "Firewalls and virtual networks" you'll need to tick "Yes" for "Allow Azure services and resources to access this server".
I was getting this error when running an Umbraco project locally, with the DB pointing to an instance on Azure. In that case, this problem happens if you haven't allowed the IP access within the Server Firewall of the DB in Azure.
You can fix this by finding out your IP and then adding it to the DB:
Click All Resources within your Azure portal, then click on the SQL Database your project points to.
Click Set Server Firewall on the right-side window.
Add in your IP as the start and end points, and call it something memorable.
Click Save and once you get the confirmation message that It has been applied, refresh your site locally.
I experienced the same problem and here is how I fixed it.
Right-click on your localhost in SSMS and select Properties
Got to the Security page and select "Select authentication" as "SQL Server and Windows Authentication mode"
Hit OK.
Go to Services and find your SQL Server service and restart it.
Check your local umbraco website now, you should be able to see it without any issues. If you still have problems, then you might need to check your local setup and permissions.
Further details are below and on this blog post.
Error:
An attempt to attach an auto-named database for file C:\Documents and Settings\xxx\My Documents\Visual Studio 2010\Projects\IncomeAndExpenditure\IncomeAndExpenditure\App_Data\Transactions.mdf failed. A database with the same name exists, or specified file cannot be opened, or it is located on UNC share.
At the start of today I was happily accessing my MVC3 application's data in a SQL Server Compact Edition 4 .sdf data file. I now need to access this data from an Android app, but the Android app cannot connect to a .sdf file, it needs a connection to a .mdf file.
So I changed the database in the ASP.NET MVC app to a SQL Server Express and a .mdf file. So far so good, after much connection string changing the application runs under VS and connects to the new .mdf and allows read/write as expected.
Unfortunately now when I try to access the ASP.NET MVC app directly through a browser (I am running everything on localhost incl. VS, SSMS) I get the error as above. I have spent most of the day going back and forth as per many many posts here, MSDN and elsewhere to the point actually where the browser hung and I lost the will to live.
So after advice from the many posts this is I have tried so far in order to connect from both VS 10 and from MSIE 8 browser:
Placing database .mdf & log in SQL Server Express default data folder
Placing .mdf in |DataDirectory| (App_Data) folder
Adding new users in SSMS
Changing user permissions in SSMS
Altering User Instance=True / False in connection string
Attempting to connect after Attaching and detaching database .mdf & log files
My question:
Is there a straight forward guide somewhere that gives details of 'EVERYTHING' that needs to be done/considered when trying to swap a datasource from a SQL Server Compact Edition .sdf file to a SQL Server Express .mdf file?
I am using: XP, VS10, SQL Server 2008 R2, MSIE 8
Thanks, carl
Hi i have a working app that uses an attached mdf file with the following connect string :
<add name="SqlDataContext" connectionString="Data Source=.\SQLEXPRESS;Integrated Security=true;User Instance=true;AttachDBFilename=|DataDirectory|\WPCloudApp26.mdf;Initial Catalog=WPCloudApp26;MultipleActiveResultSets=True" providerName="System.Data.SqlClient" />
I am using a Windows phone cloud application template and i have azure storage emulator running on my pc
everything works fine, until i do the following steps for the first time:
i want to view the database so i double click the app_data/WPCloudApp26.mdf file through visual studio when the app is not running. when i double click it, the db opens up under data connections in the server explorer pane and i can see the database and all the tables. so far everything good
I am done viewing the db, so i close the connection by right clicking --> close connection.
i want to run the app again, and when i run it all hell breaks loose. i get the following error message:
One or more files do not match the primary file of the database. If
you are attempting to attach a database, retry the operation with the
correct files. If this is an existing database, the file may be
corrupted and should be restored from a backup.\r\nCannot open
database \"WPCloudApp26\" requested by the login. The login
failed.\r\nLogin failed for user 'NT AUTHORITY\NETWORK
SERVICE'.\r\nLog file 'C:\Users\michael\Documents\Visual Studio
2010\Projects\WPCloudApp26\WPCloudApp26\WPCloudApp26.Web\App_Data\WPCloudApp26.ldf'
does not match the primary file. It may be from a different database
or the log may have been rebuilt previously.
the exception is thrown on the method var firstItem = context.SqlSampleData.FirstOrDefault();
Thats it, no matter what i do, i can't run the app again. this is driving me crazy since the only thing to help is to create a new solution with a different name (thats why i got to number 26)
What is going on ? why is this happening only after the first time i try to view the database in visual studio ?
Edit
i have noticed that changing the initial catalog and mdf file in the connection string solves the problem. So where are the remnants of the db name are saved ? how can i clean up old leftovers ?
You shouldn't try to open a .MDF file that is attached to SQL Server Express. It will probably break the consistency between the .MDF and the log file.
Connect to the SQL Server Express server using the Server Explorer, or SQL Server Management Studio. (There's a free version of it for Express as well)
If you really want to open the .MDF in Visual Studio, then detach the DB from SQL Server Express first.
In .NET, you can open a SQL Express database simply by attaching the database MDF file in the connection string (that is, you don't have to have any server software installed, it just attaches to the MDF file on the fly).
When an application does this, does it obtain an exclusive lock on the database file? Or, can a second application also attach to and open the MDF file in this same way, and query the database while program #1 is using it?
You are correct, only a single connection can be open to the MDF at a time.
This can get really annoying when you open the database through your server explorer in Visual Studio, and then try to run your application.
I've caught myself doing that too many times to count, and I always invariably end up just attaching the mdf to my sql server instance.