SQL Server Management Studio - Unable to attach to an MDF file in my user profile - sql-server

I downloaded an ASP.NET MVC template onto my development machine a dropped it into the projects folder in my user profile (C:\Users\jdana\projects\gld_ember_mvcspa). An .MDF and .LDF file came along for the ride with the template. They're located here:
C:\Users\jdana\projects\gld_ember_mvcspa\App_Data
For the life of me, I can't get SQL Server Management Studio to read from or attach to any .MDF file in my user profile (I'm running SQL Server 2014 Standard on a Windows 7 box)
Here's what I've tried thus far.
The following Access is denied when attaching a database looked like a dead-match to my issue. I've given my local login account explicit full permissions to the projects folder and all child folders (making sure to logout/login afterwards).
I gave my local login account ownership of the projects folder and all child folders (making sure to logout/login afterwards).
I checked login associated with the MSSSQLSERVER Windows service, it's NT Service\MSSQLSERVER. I gave this login full permissions to the project folder (making sure to logout/login afterwards).
Finally, I launched SQL Server Management Studio with a right-click Run As Administrator.
None of this worked. My user profile folder remains inaccessible to SQL Server Management Studio.

I was faced with the same error when i changed the password to my SQL server account. The way out was to check if the files in the location you try to attach from are encrypted. Decrypt them(Right click on the mdf/ ldf file -> Decrypt). Then try attaching. This worked for me. Thanks to the helpdesk guy in my office:)

Run Sql Server Management studio as Administrator, and login to sql server with sa or admin credential. If mdf file is uncorrupt, then it will work.

Related

Visual Studio debugger can't login to SQL server

I have a simple EF Code First project that has to create a database in my local SQL server if it doesn't exist. However, when I try to debug my application I get the error:
Cannot open database "<Database>" requested by the login. The login failed.
Login failed for user 'MicrosoftAccount\someone#me.com'.'
I somewhat understand that because I login to Windows with my Microsoft account.
So I changed my connection string from using integrated security to username and password.
I made sure the user is created on the SQL server (Login & sysadmin rights) but it still fails when I debug in Visual Studio.
So..... I build the project and ran the application directly via the exe file and everything works. But I want to understand why it doesn't work with the debugger.
Have I missed something obvious here?
So I found the problem.
My local Windows account was paired with my Microsoft account. For some reason Visual Studio sends my Microsoft account to the SQL server to authenticate even when run under specific local credentials.
My solution was to create anew local user on my workstation with NO assosiated MS account.
I made the account member of Administrators and gave it permission to the SQL server then everything was fine...
Please ensure the server and database name are specified correctly in connection string. I had a typo, and got the error.
I guess that the debugger runs with different credentials (or could be set to do so). Especially if your account is not admin.
Maybe this helps: https://blogs.msdn.microsoft.com/greggm/2008/05/15/visual-studio-remote-debugger-service-user-account-requirements/

File sharing with a specific user in database in SQL Server

I have created a login in SQL Server. The login has only read-only permissions. Database role membership for this user are db_backupoperator, db_datareader, db_denydatawriter and public. I gave him permissions to make backups, but when I try to access folder directory of the system it shows an error like in the picture below.
How can I share a specific folder to this Login in order to save backups to this folder?
Here is the error:
The user logs in to the SQL Server instance via a SQL Server logon, and asks for a backup to be made.
The SQL Server process, running under whatever Windows Identity it
is (LOCAL SYSTEM on my dev machine) makes the backup.
The user who asked for the backup in step 1 uses Windows Explorer to
check the backup folder. Note that Windows Explorer is using his
Windows Identity (NOT his SQL Logon) to check whether or not he has
access to that folder
Windows Explorer decides that this Windows user does not have access and
displays the message you show above.
To change the outcome, you need to give the Windows Logon that the user is using access to the backup folder. To do this, log on as an Admin, right click on the folder in explorer and select the Security tab. Add the Windows Logon that the backup person uses and give read access to the folder.
Just to clear, the backups are likely being done properly (absent any other data), but his WINDOWS logon is not allowed to see them.

Creating SQL Server database in (or attaching from) Google Drive

I tried to create a new SQL Server database in my Google Driver folder but I cannot even navigate to my GD and when I paste in the path I keep getting acces denied even when SSMS is running as Admin.
Also tried creating the DB in usual SQL Server Data folder, moving to my Gooogle Drive and attaching from there by pasting in the path because I cannot navigate to GD when trying to attache an existing DB but again I get access denied error...
Anyway, did anyone manage to create in or attach from Google Driver folders an SQL Server database or has any idea how to achieve this?
SSMS may be running as an admin, but the service account that SQL Server is using is the one that needs access to the folder. Can you verify that is the case

Visual Studio Server Explorer Error: Login failed for user DOMAIN\USERNAME

After creating a database file in Visual studios server explorer earlier this month my domain name of my computer was chaned (lets say previously is was OLDDOMAIN and now it is NEWDOMAIN) After my domain name had changed i am now unable to access any of my database files. I am also unable to create any new database files from Visual studios server explorer.
The error message i am getting is:
Login failed for user: 'NEWDOMAIN\GLEN'
How can i access my old database files (.mdf) or create a new one from within the visual studios server explorer?
N.B. My Authentication is set to Windows only.
You will need to Log in as a system administrator into the database server and give your new user the correct access you require. If you don't have a local user or an SA type account; you might need to log in as your old domain user to give your new domain user that permission.
If you don't have that permission; create new database server on your machine and attach the database files; (take a backup of the originals) you should then be able to access your content again.

Problem with ASP.NET Membership API connecting to sql express

While installing SQL Server 2005, I unknowingly uninstalled the existing SQL Express(I dont know 2005/2008) , but then I installed sql express 2005. But now the membership api is not able to connect to the sql express database. When I run my application with the Visual Studio 2008 , and try to login into my application I am getting the following error ,
"Failed to generate a user instance of SQL Server due to a failure in starting the process for the user instance. The connection will be closed."
SQLExpress database file auto-creation error:
The connection string specifies a local Sql Server Express instance using a database location within the applications App_Data directory. The provider attempted to automatically create the application services database because the provider determined that the database does not exist. The following configuration requirements are necessary to successfully check for existence of the application services database and automatically create the application services database:
If the applications App_Data directory does not already exist, the web server account must have read and write access to the applications directory. This is necessary because the web server account will automatically create the App_Data directory if it does not already exist.
If the applications App_Data directory already exists, the web server account only requires read and write access to the applications App_Data directory. This is necessary because the web server account will attempt to verify that the Sql Server Express database already exists within the applications App_Data directory. Revoking read access on the App_Data directory from the web server account will prevent the provider from correctly determining if the Sql Server Express database already exists. This will cause an error when the provider attempts to create a duplicate of an already existing database. Write access is required because the web server accounts credentials are used when creating the new database.
Sql Server Express must be installed on the machine.
The process identity for the web server account must have a local user profile. See the readme document for details on how to create a local user profile for both machine and domain accounts.
Actually I am using ASP.NET MVC, and by default it has the membership functionality in the web application template, and that too is not working.
you need to change the settings of the sql server express service - refer here
Try deleting the SQLExpress directory which should be at C:\Documents and Settings\username\Local Settings\Application Data\Microsoft\Microsoft SQL Server Data\SQLEXPRESS directory.
Then restart your machine.

Resources