SQL Server 2008 R2 database not accessible after instance started - sql-server-2008

This is a bit of a problem! I had shut down an instance on SQL Server and today I started it up again.
However one of the databases (the main one that I work with) is not accessible.
When I attempt to expand the database in SSMS to view tables, I get the error:
The database is not accessible. (objectExplorer)
I found this article which looked like it may solve the issue (assuming that it is a permissions issue) but that did not work either: http://sqlserver-help.com/2012/02/08/help-i-lost-sa-password-and-no-one-has-system-administrator-sysadmin-permission-what-should-i-do/
In the SQL Server error logs I am seeing:
FCB:Open failed: Could not open file E:\\.mdf for file number 1. OS error: 32 The process cannot access the file because it is being used by another process.
There is plenty disk space and so I am stuck with what the issue is.
I do have a recent backup so I'm not overly concerned about losing this database but still - I would like to be able to recover it if at all possible.,
Any help appreciated.
UPDATE - I used ProcessExplorer which showed that sqlservr.exe is using the file EVEN AFTER STOPPING THE SERVICE!
When I attempt to detach the database I get an error about Primary files do not match or that log file is from different database. Confusing!
Thanks.

No idea what the issue was still - but it was resolved by rebuilding the log file.

Related

Export table from Xampp MySQL from file directory

I have an error with Xampp where it will not connect to my database. I have had this error several times in the past and no solutions have helped. I find that uninstalling and reinstalling ends up being the fastest method, however, by doing so I lose my database tables. As I have no access to the default export and import functions, I was wondering how I transfer the tables across.
Last time, I copied and pasted these files into the same directory when I reinstalled Xampp and the tables transferred but the data within did not. The tables had also lost some functionality as well.
If anyone has any methods to do this I will greatly appreciate it.
The best way to backup and restore your data is to dump the database to an SQL file. You can use the provided mysqldump tool for that, which is the best tool for the job.
Copying the entire MySQL "datadir" (which is probably one level up from the screenshot you've posted) and completely replacing one of your new stopped MySQL instance will probably work, but is not reliable and is not supported. Since there are other files (such as ibdata1) that handle the overall health and functioning of the entire MySQL instance, you can't only copy over individual database directories. Furthermore, you should only do this when the original and replacement MySQL servers/daemons/services are completely stopped because otherwise there are file corruption or concurrency issues.
Since you're running the server on your own computer, you should grant yourself sufficient access to be able to use mysqldump and use that regularly as a backup, since file-level backups of the data directory are not reliable.

MySQL Workbench Data Export error. "Error executing task [Errno 2] No such file or directory"

I have a problem to export a small database using MySQL Workbench's Data Export function on Windows 10.
Previously I have had no problems exporting and importing databases, although after this happened I have changed the security of the server to legacy to get it working with phpMyAdmin using the MySQL Workbench Installer, which I have been unable to change back as when trying to execute the change I got an error stating the installer was unable to create the temporary user (running this as administrator didn't help).
Since then I have also updated MySQL Workbench, the server, and the rest of the components that were installed with it, which seems to have gotten rid of the MySQL Workbench Installer application, as such i am unable to provide the exact error it gave regarding being unable to create the temporary user.
I'm not 100% sure if the above is relevant to the issue but it does seem like it could be related.
The issue that I'm trying to fix is that MySQL Workbench will not export any (or all of) the databases I have set up to a self contained file. The error I keep getting is below:
09:47:47 Dumping va_form (all tables)
Error executing task [Errno 2] No such file or directory: u'D:\Mike\Desktop\Dump20190226.sql'
09:47:47 Export of D:\Mike\Desktop\Dump20190226.sql has finished
I was previously getting a similar error about access denied, which then lead me to change the default dump directory to my desktop, as I'm only going to need to dump files occasionally and sort and send them elsewhere straight away.
I have also tried disabling column-statistics and lock-tables although this has had no effect.
As you can see, at the start of the directory it's trying to dump to it says "u'D:\\" - I am not sure if this leading u is significant, although it is not there in the directory I have specified to dump the file to.
I'm hoping someone here has some insight into this issue, I have no idea why MySQL Workbench's installer was refusing to make the temporary user (even when being run as administrator) and why I cannot find the installer now, as well as the obvious problem of why MySQL workbench is unable to create the file to dump anywhere on the system.
Thanks very much for your time reading this.
It is probably an issue with a recent update of Windows Defender, not with MySQL.
Try to save your dump to folders located somewhere else than Desktop or Documents (I usually send them directly to a cloud service integrated with my OS). If this works, you just need to add an exception for MySQL in Windows Defender.

Linked server infinite load/wait after server name change

I have been stumped on this for this whole day now. I use MS SQL Server 2008. I have alinked server pointing to a DB2 database using an ODBC connection that has been running fine for years. Today I decided to change the name of the server and now whenever I run an openquery, run a job that connects to this linked server or when I try to see the tables of this linked server the query/job will run permanently and the tables forever say [Expanding...] but they never actually show. When I try to cancel a query that is stuck, it will never finish canceling. The only way I have found to actually stop queries is to log my account out and end my session forcefully (MS SQL server will tell me it cannot shut down but I can log my Windows account out get past it).
We already tried to recreate this exact linked server by scripting it and using a different linked server name but this gave the same result. I also tried recreating this linked server on another actual server and that worked fine. The server where the linked server is "stuck" on, works perfectly fine as long as I don't try to connect/communicate to these broken linked servers.
My question is basically, what in the world happened when I just changed the name of this server and does anyone have any suggestions on resolving this? I have pondered about a complete server restart, but since this concerns a production server this would be my absolute last resort. I however see no other options right now.
Solution was to do a complete server restart and to back up to an earlier date. We have done the exact same thing after that and everything worked fine, so it seemed like it was a one time critical anomaly.

MySQL table crashes only after repair

I am using WordPress with MySQL. My site recently crashed (due to some out-of-memory problem with the database)
Once the site was up, it seemed fine, but just in case I ran "repair" (from phpmyadmin) on the DB. After that, it crashed my "wp_posts" table. I restored the DB from an older version, again - the table seemed fine. Again, I ran the "repair" and the same table crashed.
I am on a VPS server. So I don't have root access, but I can ask the web admins to check things.
Any idea what might be causing this / how to solve it?
Thanks.
This is a MySQL server configuration problem. I've had the same problem. In my case it was due to a MySQL system variable called myisam_sort_buffer_size being set to an absurdly small value (4096). This interfered with the repair table operation. In my case, the wp_posts file and others used the MyISAM access method. If yours use InnoDB, you'll want to look at the variables controlling that access method rather than MyISAM.
Issue this command to your MySQL server:
show variables like '%buffer_size'
Then look for variables which seem low.
You may also want to look at the MySQL server error log file.
If you run the server yourself, please be careful making configuration changes: Read the doc page first. http://dev.mysql.com/doc/refman/5.6/en/server-system-variables.html
If your hosting provider runs the server, put in a request ticket, ask that it be escalated to a support person who knows about MySQL, and be specific about what is going wrong.

MySQL Workbench - migration of the data doesn't work

I'm trying to do a migration through MySQL Workbench, from one server to another. It sets the schema okay, but when it comes to the data, it fails. It doesn't give me much information either - the output resembles this:
`schemaname`.`GeneralCodes` has FAILED (0 of 3 rows copied)
That's all it says. Can anyone point me in the right direction?
I found out what the "The network name cannot be found" message meant, at least. I was using the network at work to store my dump files, as in "\\myserver\horndinkle\dumps\xxx". It was referring to that, that MySql Workbench couldn't read from there, not the network name I was migrating to/from. Once I put the file on my local machine, it worked just fine.