SQL server 2008 R2 cannot attach database - sql-server-2008-r2

Basically I want to attach .mdf file which located in D(you can see it from the picture), But then I got this error.
Any idea why this happened and how to fix it?

There may be two solutions for that
1) You may start the sql server management studio application by right clicking and selecting the "Run as administrator" to run it and then try to attach the database in D:
1) You may put your database in the default directory of your database like C:\Program Files\Microsoft SQL Server\MSSQL10_50.MSSQLSERVER\MSSQL\DATA etc ....

Related

Connecting to localDB in Rider gives the wrong DB

https://blog.jetbrains.com/datagrip/2016/10/07/connecting-datagrip-to-sql-server-express-localdb/
The description above worked fine. But the opened DB contains system tables like spt_monitor, spt_fallback_dev. (sqllocaldb.exe i showed only one localdb)
I have an mdf file which contains the DB I want to use. Any idea? (I tried to give the full name of the mdf file in the uppermost Database field, but it did not help)
One more info: In visual studio sql server object explorer, I see the system databases and the mdf files as well. In vs / server explorer I can connect to the mdf file.
I found the solution:
after giving username and password go to schema tab
(exit from visual studio)
check the mdf file, check the relevent schema, e.g. dbo
if you missed this step then database double click on "connection / schemas" to make the check

Database MSDB can not be opened

I have got this problem in local instance of SQL Server 2008 R2 on my machine. There are several databases on this instance. But I am not able to see any of them from the object explorer.
I am able to query my databases from the new query window. But not able to see any of them.
Whenever I try to explore the databases I get this error :
Database 'msdb' cannot be opened. It has been marked SUSPECT by recovery. See the SQL Server errorlog for more information. (Microsoft SQL Server, Error: 926).
I have tried
Refreshing the connection
Reconnecting the connection
Restarting the service Sql Server (MSSQLSERVER).
Restarting the SQL Server Management Studio
Restarting my machine
I have also tried combinations of above, but nothing works.
My operating system is Windows 7 Ultimate (64 bit).
SQL Server Management Studio Version is 10.50.2500.0.
I found my answer in this link.
EDIT : Including both the solutions from link because of possible Linkrot in future.
Login with sa account, for both the solutions.
Solution 1
Open new query window
EXEC sp_resetstatus 'DB_Name'; (Explanation :sp_resetstatus turns off the suspect flag on a database. This procedure updates the mode and status columns of the named database in sys.databases. Also note that only logins having sysadmin privileges can perform this.)
ALTER DATABASE DB_Name SET EMERGENCY; (Explanation : Once the database is set to EMERGENCY mode it becomes a READ_ONLY copy and only members of sysadmin fixed server roles have privileges to access it.)
DBCC checkdb('DB_Name'); (Explanation : Check the integrity among all the objects.)
ALTER DATABASE DB_Name SET SINGLE_USER WITH ROLLBACK IMMEDIATE; (Explanation : Set the database to single user mode.)
DBCC CheckDB ('DB_Name', REPAIR_ALLOW_DATA_LOSS); (Explanation : Repair the errors)
ALTER DATABASE DB_Name SET MULTI_USER; (Explanation : Set the database to multi user mode, so that it can now be accessed by others.)
Solution 2
In Object Explorer --> The opened connection item --> rightclick --> Stop
Open Control Panel --> Administrative Tools --> Services
Select Sql Server (MSSQLSERVER) item from services --> rightclick --> Stop
Open C:\Program Files\Microsoft SQL Server\MSSQL10.MSSQLSERVER\MSSQL\DATA
Move MSDBData.mdf & MSDBlog.ldf to any other place
Then Copy this Files Again from new place and put it in older place
C:\Program Files\Microsoft SQL Server\MSSQL10.MSSQLSERVER\MSSQL\DATA
In opened connection in object Explorer --> rightclick --> Start
Then Refresh DataBase.
Then you can Detach the MSDB File
The 2nd solution worked for me.
Note : I had to get "msdb" database mdf and ldf files from another working machine to get it working.
What instantly fixed my issue was to replace existing MSDBData.mdf & MSDBlog.ldf files
in C:\Program Files\Microsoft SQL Server\MSSQL10_50.SQLEXPRESS\MSSQL\DATA. I got these 2 files copied from another working machine, Stopped the SQL service running in my machine, removed the above existing 2 files from their location and added the new 2 copied. Once I restarted the service , issues has been fixed.
Try this
Set the database into single user mode:
Alter database dbname set single_user
Now set the database into emergency mode:
Alter database dbname set emergency
Repair missing log file or corrupted log file with data loss.
DBCC CHECKDB ('dbname', REAPIR_ALLOW_DATA_LOSS)
Now set the db in multi user mode;
Alter database dbname set multi_user
You may loss the data by using this command. It also depends on client's approval. To avoid this you may use some other dedicated software ( As Mentioned here ) to recover from suspect mode.

SQL Server Agent gives- Remote procedure call failed (0x800706be)

Does Anyone knows the solution to this problem m not being able to run the SQL Server Services.
Solution: Install SQL Server 2008 R2 SP2, restart, open SQL Server Configuration Manager and ALL is good.
Source: Frozen bytes
No need to re-install or update your SQL Server 2008 R2 instance. I got the same error and it get resolved by simply starting the MSSQLSERVER standard service.
How to start this service:
Open Administrative Tasks > Services > Select Standard services tab > start SQL Server Agent(MSSQLSERVER) service and you are good to go.
With all due respect, "Right click on configuration manager and run as administrator" is a bogus answer. I also have this problem with the following series of events: I download the Windows Azure SDK from here: http://www.windowsazure.com/en-us/develop/downloads/, which installs SQL 2012 express; immediate I try to run SQL Server Configuration Manager, and the installation of SQL 2012 has broken it such that I get the "remote procedure call failed". That is true even if I "run as administrator". Microsoft says they can't reproduce this, but I've contacted them again because I've now reproduced this twice. And, if there's any doubt: un-installing SQL 2012 causes the problem to go away, and the configuration manager works again. I blogged about it here: http://dbarrowstechblog.blogspot.com/2012/09/the-remote-procedure-call-failed.html ; haven't solved it yet.
This error occurs only after I have installed the Microsoft Visual Studio 2012 setup in my work machine.
Since it is being a WMI error, I recompiled the MOF file –> mofcomp.exe "C:\Program Files (x86)\Microsoft SQL Server\100\Shared\sqlmgmproviderxpsp2up.mof"
I also un-registered and re-registered the sql provider DLL –> regsvr32 "C:\Program Files (x86)\Microsoft SQL Server\100\Shared\sqlmgmprovider.dll" but issue not resolved.
Solution:
I have applied SQL Server 2008 R2 SP2 on my SQL 2008 R2 instance and that fixed the issue with Sql Server Configuration Manager. You can download setup from here... http://www.microsoft.com/en-us/download/details.aspx?id=30437 .
Ok, Stop this.
Is this a new Installation?
Open SSMS in Integrated security Mode
Right click on server name in Object explorer tree at the left
Select properties -> Then choose the "Security" page at left
Under Server Authentication, select "SQL Server and Windows Authentication mode"
Click OK
Exit SSMS completely
Open "SQL Server Configuration Manager" (in Configuration menu under the "Microsoft SQL Server 2008 R2" menu item from start menu
Select you instance on SQLExpress and restart the instance of the server (but this is ok for non express too)
Exit SSCM - and to verify open SSMS again, but with "SQL Server Authentication" selected in the Authentication type dropdown - put in your SQL user ID and password.
installing the SP3 on SQL server 2008 worked for me..so give it try
Thanks!! dont forget to vote up if this helps you

Attach database to SQL Server 2008 R2

How do i load a database into SQL Server 2008 R2 express? SQL Server 2008, have a right click function on databases to add it. R2 don'r have the database folder. I checked the FAQ as best I could to find an answer but found nothing.
Thanks
I'm not quite sure, if I understand the question, but I read it as you do not have a "Databases" folder under the connected database server. I am thinking if the problem is more on the connection..
I assume that you mean SQL Server Management Studio.
In my understand you can't create a database.Right click and add.Something missing in your installation.Try to full install it again.. or try to create using Query
Create Database <DB NAME>

Automatic "Script database as... create" for SQL Server 2008

I'd like to make a daily automatic creation of the creation script for a database in SQL Server 2008, meaning having a (bat, exe, ... whatever) that creates a text file with the very same output obtained by right-clicking on the database in SQL Management Studio and do Script database as... --> Create to... --> New Query window.
Any hint?
Thanks in advance,
Mauro
EDIT 1: We already used SMO but a couple of things are annoying
Needs compatibility pack in SQL Server 2008 (confirm?)
Some things were not created in script (some indexes and keys and in table creation schema is lost)
Best choice for me would something with a powershell script but any other idea is welcome!
You can use SMO. For example: http://www.sqlteam.com/article/scripting-database-objects-using-smo-updated (see the Scripting Objects section).
More info on SMO: http://msdn.microsoft.com/en-us/library/ms162169.aspx