VS2019 MVC Database solution won't work on a second machine - sql-server

I had created a webpage with DB access which works perfectly well on the machine I develop it. However, when I copy everything across to another machine, it fails with an error message - cannot open database xxx requested by the login. I did copy everything including the database created in the development environment and put it in the same place as the development did. What other thing I had done wrong ? Please help. In addition, when I open the solution on another machine, I cannot see the database from the SQL Server Object Explorer like what I saw on the development machine.

Problem solved ! Need to copy the database and the log file across and the used the SQL Server Manager to attach the database to the right server. After that, everything just work !!

Related

Make SQL Server LocalDb portable

I'm setting up a new machine and to my surprise it is really difficult to get the localdb working on a new machine. Everything in my solution explorer populated, but nothing shows up in my (localdb) project after I fetch from source (using git).
What is the best way to get my localdb project from my old machine to this new one?
In an ideal world, what i'd like to do is have it set ups so then when some pulls the SSDT project down from our source they can hit deploy and completely populate the localdb project on their machine. Has anyone done this before, know how to do this?
--Disclaimer--
I feel like when talking about localdb it's important make some clarifications, because it seems that when other people post questions like this they get a lot of responses that apply to SQL Server databases.
What a localdb project is:
A localdb SQL Server project is a special server instance that runs only
when its connected to and acts partly like a SQL Server and
contains special instances of databases that only run when a
connection is made to them. A localdb can be used for certain types
of production, but they are most often used as a means to test other
databases.
What a localdb project is not:
A localdb project is NOT a SQL Server database.
I'm well aware that I could back up every DB in my project and manually recover them on the new machine, but that is not what I'm looking to do.
You can achieve this by detaching and attaching process.
Step 1: Find the location of the localDB database.
Right click on the database name and select properties
From the Data File property, you can find the database current location.
Step 2: Detach the current database
EXEC sp_detach_db 'aspnet-IdentityApplication-E2BBF1E6-123-4567-8910-07BC0413419B', 'true';
Step 3: Copy and Paste the localDB to the different location (The location where you want to put the localDB database)
Step 4: Attach the database with the new location
CREATE DATABASE [aspnet-IdentityApplication-E2BBF1E6-123-4567-8910-07BC0413419B]
ON (FILENAME = 'D:\Test\aspnet-IdentityApplication-E2BBF1E6-123-4567-8910-07BC0413419B.mdf'),
(FILENAME = 'D:\Test\aspnet-IdentityApplication-E2BBF1E6-123-4567-8910-07BC0413419B_log.ldf')
FOR ATTACH;

Publishing a VB.NET Application with SQL Express DB (using LocalDB)

I have written a VB.Net application that uses an SQL Express DB file containing a single table and a handful of stored procedures.
I have successfully built and exported the application to my VPS.
The problem comes when knowing what to do concerning the database file, there is a wealth of stuff online but not specifically to suit my needs.
I plan to use LocalDB on the VPS but being commandline - it is hard to know if the scripts that I have run have been successful after creating an instance , starting it... etc,
I want to keep installation requirements to an absolute minimum on my VPS machine and (in time other end users machines)... hence using LocalDB and not SQL Express
So, what do I have to do on the VPS to enable my application to connect to the database.. ? This was simple when it was Access - (supply the MDB file and run the AccessDatabaseEngine(redistributable) - job done)
The connection on my devt. machine runs as expected.
The connection string in my code is:
Const strSQLConnection As String = "Data Source= (localdb)\v11.0;Database=SoccerTrader;Trusted_Connection=True"
Can anyone help please.. this is driving me around the bend.. surely it cant be that difficult..?
===========================
I have found the following in an MSDN blog which says:
Database as a File: LocalDB connection strings support AttachDbFileName property that allows attaching a database file during the connection process. This lets developers work directly with databases instead of the database server. Assuming a database file (*.MDF file with the corresponding *.LDF file) is stored at “C:\MyData\Database1.mdf” the developer can start working with it by simply using the following connection string: “Data Source=(localdb)\v11.0;Integrated Security=true;AttachDbFileName=C:\MyData\Database1.mdf”.
================ ADDED 12th June =====================
OK, this is really bugging me now... I have read around this till it is coming out of my ears and nothing specifically seems to target what I am trying to do. All the blogs I read refer to installing / running SQL Server and changing permissions etc.
As I have mentioned I am using a VPS and propose to use LocalDB on the VPS to access a simple/small database file for a VB.Net application I am writing.
This is the story so far.
1) I have built a working prototype on my development PC and connected using SQL Express to a database file SoccerTrader.mdf - no problem.
In the Visual Studio Project properties I have added a requirement to the project that checks for SQL Server ..and if it is missing, installs it...
2) I install the project on the VPS and as expected SQL Server 2012 LocalDB is installed .... see here..
3) I have copied the SoccerTrader.MDF and SoccerTrader.LDF files into "C:\BESTBETSoftware\SoccerBot" on the VPS
4) for practical reasons given the problems I am having getting this to work, I have implemented an inputbox for me to specify the connection string when the application runs.... the connection strings I have used give the following...
1]: http://i.stack.imgur.com/i2tro.png
I have not changed any file permissions on the development PC and the database state is NOT read only....
So, the question is where do I go from here...? What have I missed.. why is it not working..?
I have managed to sort the problem.
Seemingly, the connection string I was using was OK. It was my error handling that wasnt 'clean' enough. It transpired the connection was being made on my VPS but when the application attempted to update the table , the directory I had created and put the MDF file into, would not permit write access.
I moved the MDF into the C:\Users\Public\Documents folder and all works as it should.
You have to specify the full path of the Db file with folder name/ip-address

setup and deployment visual basic 2010, ms-access database not found after installation

im using MS-access as my database. I've already finished the project and it is working perfectly fine.
my database location while im still developing is in C:\Users\Users\documents and the other one located at C:\Users\Users\documents\visual studio 2010\projects\project1\project1\bin\debug
is bad to put the database at two different folder?
1st problem: now creating a setup and deployment project, i use setup wizard and checked all then build it. installation of setup is successful but when i try to run the program, it doesnt respond,
2nd problem: i cant see my 1st database located at program files, only the second one and maybe this is the cause of unresponsive app.
copying the debug files into other computer and copying manually my database to user\document which i have to change permission and the copied debug files runs well, but i have to create an installer. how to do it?
from my server explorer i was wondering there is only one database, yet my program works fine when running debug? reconnecting the unseen database would be a lot of work because it is my main database.
You should check the database which is connected to your project and the path which is associated.
Try Application.StartUpPath in your connection.

SqlExpress Db Is in use by system

I have a strange problem that is reoccurring. My app is a MVC5 application using EF code first and SQLExpress. My solution uses 4 databases - 3 of which work without a problem. The fourth database is constantly 'acquired' by 'System'. Everyday for the last week when I boot up I have a problem.
When I run the app and the DatabaseInitializer runs I get this exception :
Cannot open database "databaseName" requested by the login. The login failed. Login failed for user 'Computer\UserName'.
Weird. I read some S.O. articels about changing permision, but that smells to me. This database shouldent be in someone elses domain in the first place! The other databases work fine !
So I go about deleting the database. I get this error.
Error deleting file 'database.mdf'. The process cannot access the file because it is being use by another process.
So I reboot and go to delete the database directly from the windows explorer.
The action can't be completed because the file is open in System
I was finally able to delete the file by running my PC in safe mode and deleting it there. Im not sure what the cause of this is. I am running SQL express and I don't see any SQL background services running.

Need help on replacing access db file on deployed project in visual studio 2005

I have a VB based VS2005 appl developed using Access DB a few years back on Windows XP and it has been working fine until moving to Windows 7. I re-built the solution by changing to the x64 platform also at the sametime modified the Access DB a bit resulting in a new Access DB file to be included in the solution. When I debug in VS2005, I have the new version of DB residing in my project\x86\Release folder and successfully access this new version.
Problem is that once I create the solution for deployment, the deployed application kept on opening the OLD version of the access database (mdb) file. I was not able to find where is it opening the old version of DB from even after I removed the mdb from the installed folder. I have been a lot of digging and research on web and not able to find out how to solve this problem.
Can someone please help to tell me how I can have my deployed appl to open the new version of DB ?
Thanks in advance
It sounds like you are not allowing for virtualisation - do you know about this? For security reasons after XP (Vista onwards) Microsoft doesn't allow writing to the Programs folder and if it encounters an application attempting to do this makes a copy of the files trying to be written to (in your case an Access database) and places it somewhere (can't remember exactly where at the moment) hidden from casual user.
For example, if you look at the database on your Win 7 machine in the same location at your .exe file I should think you will find it is unused - and since it was installed on the machine the OS has been redirecting requests to read/write to your database to the virtualised copy it created for you.
So, first of all find this other copy (sorry I'm currently on a mac and can't remember the location) and see if that contains data that your application is creating. Then try substituting your new database (making a a copy of your old one first of course) and seeing if your application is reading/writing to it OK.
Then it is a matter of handling replacement of databases during application installation.
However, you should give serious consideration to placing your database in a location which is not virtualised!

Resources