Where are my Local SQL Server Express Database Files? - visual-studio-2019

I read that my Local SQL Server Express Database Files should be located here (since user on my machine is "bclay"):
C:\Users\bclay\AppData\Local\Microsoft\Microsoft SQL Server Local
DB\Instances\MSSQLLocalDB
...but that can't be, as the newest file there is over 2 months old, and I updated SQL Server Express data today (via my C# Winforms app, created with Visual Studio 2019). How can I sleuth out where those files are, so I can back them up?
UPDATE
Using the answer from marc_s, I was able to get that from Visual Studio's Server Explorer:
UPDATE 2
Okay, this seems bizarre: I navigate to that location in Windows Explorer, and it won't show me what's in the \Data subfolder. Although I have selected the Data subfolder, it is showing me what's in the Installs subfolder below it, and when I right-click the Data subfolder to czech out its properties, it tells me I don't have the credentials to view it:
How can I backup the .mdf file if I can't even see it?
UPDATE 3
I did a hard-drive-wide search for all *.mdf files, and it does not "find" (show me) my tables. The only ones that could be related are the top ones here, but they have generic names:
UPDATE 4
I think it was marc_s that mentioned somewhere to use MS SQL Server Management Studio, and to select Task > Backup. I downloaded/installed it, and it seemed to work: it did create a Backup folder in the expected location. I see that it was created today, 10/1/2020, but I still can't see anything in the folder, thus I can't copy anything from it. Here's what I see (the contents of the last-selected folder) when I select the "Backup" folder:

In SSMS, if you're connected to the database in question, you can run this query
SELECT *
FROM sys.database_files
and the physical_name column in the result set will show you the path of the files in question

As #marc_s said, since you've found where are located the MDB file, just copy them on your USB stick and you are done.

Related

Sync references with TFs in VS database projects

In db projects, when you add a database dac-pac for example as a reference use in a view to reference a third party database, that seems to be valid only for your local copy.
In VS 2015 I can;t seem to find how you add that as a build so that it syncs and compares with the version you store in source control.
If I check out a team project, create a view referencing a third party DB, create a dac-pac for that DB, add it as a database reference, save, build, check in, by default that reference isn't checked in to the server for another developer to check out in the latest version and therefor they will get reference errors.
Does anyone know how to sync these? I can't find an option to do so!
Also, it would be nice to be able to edit the dam things, For example if they are on a different server you must define that. But say the server changes, you can only edit it in your publish profile, however if you do that but someone else doesn't it will flag as a change for them.
You'd better add the .dacpac file to TFS version control. When others check out from other machines, get down the .dacpac file together with that db project.
Make sure that when other check out that file and the db project to their local machine, the relative path between them are same with that in your environment. Actually, in the .sqlproj file of your db project, it has defined the relationship.
For example, I put the .dacpac file under a folder named "DACPAC" and this folder is at the same level of my solution folder.
In the .sqlproj file:
<ArtifactReference Include="..\..\DACPAC\TestDB.dacpac">
<HintPath>..\..\DACPAC\TestDB.dacpac</HintPath>
......
</ArtifactReference>
Note: The "..\" mean go to the uplevel path from where the .sqlproj at. It has 2 "..\", so go 2 uplevels.

App_Data folder is not checked in with Team Foundation Server [duplicate]

I am working with ASP.NET C# MVC 5.
.mdf/.ldf files in App_Data do not appear on Pending Changes in team explorer. Therefore I can't check them into TFS(visual studio online). I've tried recreating the project a few times and none worked. What might be the cause for this?
Go to Team Explorer and locate Excluded Changes and you should find it excluded. Right click the App_Data folder and include it.
But you might want to reconsider including the database files. As you're developing and testing, every little database interaction will trigger a change and most of those are trivial. Also, if someone else is working on this project, they may not want your database file to overwrite theirs when they Get Latest Version.
If you're using Entity Framework Code-First, the database is automatically generated when you build the project I believe, otherwise you just run the Update-Database command to do it. This lets everyone collaborating have their own local database file to work with. You can also utilize migrations to make updates to the database structure. If you want the database to be generated with pre-populated data, you should utilize the Seed method.
This is a general question. As already answered by 'Ty Morrow' in above comment there is an initial Seed Method in Entity Framework which ensures that all values are inserted. However there are many scenarios that you also need to work with the latest added / removed DB entries not present in the seed method.
Please perform the following steps to ensure that your data directory file is included in the source control.
Click App_Data folder and on encircled toolbar click on Show All Files as shown below in the snapshot
Right Click on your MDF (Data Source) File and click on Include in Project
Right Click again on your MDF File and click on Include in Source Control
Simply Check in the file by Right Clicking on root project folder link and file show be now part of Source Control

Unable to check in after adding database files to TFS databases

Slight difficulty with Team Foundation Server 2008 databases (using Sql Server 2005).
Team System reported running out of disk space so I added another data file to each and every Team System database (on another fixed drive) to increase the disk space available. I did it as follows for each TFS database:
Add another file, type=Data, size etc = defaults, path to new drive.
Change the original data file to stop further expansion (Autogrowth=none).
Restart Sql Server.
That is the documented method for adding further space to a Sql Server 2005 database. However now I find I can check out files, but not check in. In Visual Studio, Source Control Explorer displays projects and can be expanded to show folders and files as normal, but When I rt-click on a checked-out file and select 'check in', nothing happens and the file remains checked out, and then Visual Studio has to be terminated using Task Manager.
There don't seem to be any related errors in the server Event Log.
What have I missed or done wrong?
You need to use the 'Database Mirroring' feature to add a database file for a mirrored database that has different drives and/or paths.
Firstly, check this MSDN article for the detailed steps on how to "Configure SQL Server Mirroring for the TFS Data-Tier Server": https://msdn.microsoft.com/en-us/library/aa980629(v=vs.90).aspx
Secondly, follow steps in this article about how to "Fail Over to a Mirrored Data-Tier Server if the Principal Server is Unavailable": https://msdn.microsoft.com/en-us/library/aa980528(v=vs.90).aspx
"clean the TFS cache", posted by TfsAgent, actually solved the problem. Nothing to do with adding extra database files after all - that was a coincidence.

TF400018: Local version table locked

Got the below in TFS and VS 2012 RC, anyone know of a fix? Doesn't seem to exist on MS website.
TF400018: The local version table for the local workspace
COMPUTERNAME;MYNAME could not be opened. The process cannot access the
file because it is being used by another process
Any suggestions welcomed.
We experienced this one as well. Migrating to the RTM makes this happen a lot less, but it can still happen a lot.
When using local workspaces (a new feaure in vs 2012) a local file based database is created to administer changes you make localy. When you change a source file, this file base database needs to be updated. If this update conflicts with the normal update task which routinely checks for changes you get this error. The cause of this issue is usually that you are using local workspace for more items than it was intended or that your disk I/O is too slow.
Workarounds for this are either:
Replace your disk with an ssd. Having better I/O makes this issue
happen a lot less.
Switch back to server based workspaces. (which handles this better)
Use the TFS-GIT connector and use git for offline support.
Split your workspace mapping in portions so they contain less items.
Please delete the files under %Temp% folder and open the project as
"Run as Administrator " mode .It works for me .
Regards,
Kamaraj

Project wants to check out .dtproj in SSIS project every time TFS Get Latest is performed

Using Team Foundation server and BIDS 2008, I receive a screen to check out the dtproj file every time the Get Latest operation is performed.
Steps to Produce:
I have no files checked out after performing a "Get Latest" from solution explorer.
I click to open the solution file .sln from Solution Explorer and the SSIS project opens.
I then receive a "Check Out" screen asking me to Check Out the .dtproj file.
Any ideas how to keep this from happening?
Imperfect answer: How can I prevent BIDS from automatically checking out SSIS packages?
Also related: http://social.msdn.microsoft.com/Forums/en-GB/sqlintegrationservices/thread/654d556f-3826-4fd3-a36a-e7f20a059569
I have been using BIDS 2008 with TFS 2010 for quite sometime but never had the issue that you are facing. Here are the Source Control settings on my BIDS environment.
Some of the other links that might help you:
A project is automatic check outs everytime when i opens the solution in TFS 2008
How to stop Visual Studio from "always" checking out solution files?
This behavior appears to stop if you manually add the .database file to TFS through Source Control Explorer, making sure that the .database filename inside the .dtproj is the same name as the file you add to TFS.
Turns out the .database file is a local 'runtime' type file that Visual Studio creates each time. It is not an actual source file and should not be checked into source safe. What I think happens is that:
This file gets created by VS
At some point someone checks it into source safe, making the file read only in their working folder
Next time VS tries to create the file again. It can't (unless it's checked out) so it creates another one with a slightly different name
Because the filename is now different is changes the .dtproj file that references it. It therefore tries to check the .dtproj file out because a change has automatically been made to it
Chaos and confusion ensues
This is roughly what we did to fix this:
Delete any .database files from source control, ensure that it never gets added back again
Close VS
Backup and delete any .database files from local dev folder
Open VS and get latest
You might get 'this project couldn't be loaded' type errors in VS because the referenced .database file is missing
To get the project loaded, you need to get a valid .database file (these can get corrupted - check the file contents) into your local folder, and edit the .dtproj file in a text editor to point at the valid file
Once you have your .dtproj file working, check it in and have everyone get latest
Make sure no one ever checks in the .database file
Why oh why is it called a .database file when it has nothing to do with a database. When you search online for .database you get...... information about databases, not this annoying VS file.

Resources