"Database is locked" error when creating view in SQLite - sql

I am running SQLite 3.7.9 on a Ubuntu virtual machine (VirtualBox). I have a db called "frequency" on which I am trying to create a view:
CREATE VIEW myview AS SELECT * FROM frequency;
On running this I get the error "Error:database is locked.". (The actual view I am trying to create is more complex, but even this simple one won't work).
From what I have read online, this error usually occurs either due to 1) concurrent access, which I do not think is happening here as the db file is on the cirtual machine, or 2) running a CREATE/DROP command when a SELECT command has not finished - I do not think I am doing this either since my query is so basic.
I have also verified from ls -l that I have read-write permissions for both the file and the directory holding it.
Any help would be appreciated.

Try listing all the processes you have running, make sure you don't have two database processes running at once. Although the conditions were different, with me running a Windows VM, this fixed it.

Related

Recovering Postgres DB from Program Files

a few weeks ago my computer stopped working and I lost a lot of important data stored in a postgres DB (should have backed it up but, I didn't ** sigh ** ).
I was able to access the hard drive and extract the program files for postgres. How can I try and restore the DB?
Here is what I have tried so far:
download postgres (same version as the lost DB) on a separate computer and swap out the program files with the ones I am trying to recover. I am using a PC, so I stop service->swap out all the files-> restart service. Restarting the service is never successful.
Use PGAdmin -> creat new db (ensure path for binary files is correct) -> restore-> Here i get stuck figuring out what the correct files are

Access VBA: Shell command broken in one particular database

I have two Access databases that I'm opening on the same computer. In one, running this in the immediate window works as expected (opens Notepad):
Shell "notepad.exe"
In the other, I get this error instead:
Run-time error '5': Invalid procedure call or argument
I have not been able to come up with any shell command that will run successfully in that second database. No matter what, I get that error.
What is going on here? Could there be a security setting coming into play? Or perhaps one is an older version?
Edit - More Info
When I go to the definition of Shell in the malfunctioning database, it goes to VBA.Interaction.Shell.
I get the correct IntelliSense tooltip for Shell.
I tried VBA.Shell "notepad.exe" and VBA.Interaction.Shell "notepad.exe" without success (same error).
Here are the references that are checked in both databases:
Decompiling did not help.
The culprit was our anti-virus software! UGH!
Why did it work in one database and not the other then? I'm told that years ago, anti-virus exceptions were made for my computer for the one database but not the other.
I recommend that any others who encounter this problem check their anti-virus logs/policies. Also, running the database from another computer with different policies in place might shed some light on the issue faster. In this case, when I used remote desktop to log into a server, I was able to call shell successfully.

error when adding tableadapter to dataset

I am developing a winforms application in Vb.net
when i try to add a tableadapter to an existing dataset I am receiving the error:
Failed to open a connection to the database.
"An attempt to attach an auto-named database for file ###Filelocation### failed. A database with the same name exists, or specified file cannot be opened, or it is located on UNC share." Check the connection and try again.
This same dataset has 2 other tableadapters using the same dataconnection (as I am selecting the already existing dataconnection) which work fine
this connection is using application connection strings:
Data Source=(LocalDB)\v11.0;AttachDbFilename=|DataDirectory|\test.mdf;Integrated
server=localhost;user id=root;password=password;database=testuser;persistsecurityinfo=True
this error pops up every time I select the dataconnector on the first window that pops up.
Why is this happening
additional info:
The other 2 tableadapters were added to this dataset using a different computer
this is for a mysql connection
I found this post on the MSDN forum:
An attempt to attach an auto-named database ....\aspnetdb.mdf failed
One of the suggestions is as Mr. DonBoitnott correctly says, add User Instance=True;. But, there's also another suggestion posted by Luke A.
"For the record, not one single error message given to me during the course of trying to fix this was relevant to the actual problem. Upon first receiving "An attempt to attached an auto-named database..." I looked online for every suggestion I could find: use an absolute path to the MDF, reorder TCP/IP and named pipes in the server configuration, disable/enable UserInstance (depending on where you looked), change security settings, reconfigure authentication, give specific login credentials.
None of these worked. All of these led to different vague/ambiguous error messages, which led to another problem which required a solution which led back to the original error message... an endless loop of problems, completely unrelated to what was actually wrong.
_Also, posts about setting correct permissions on the App_Data folder are deceptive, as they imply the default permissions were not sufficient for SQL Express (in fact, they are). The whole point of this VS environment is that you can develop a web application and plop it right onto an IIS/SQLExpress setup and have it work. This makes the applications more portable (within IIS, of course) and secure. Of course, everything configuration-related has been obfuscated enough to make it several orders of magnitude more difficult than it has to be."_
So: Try prepend Initial Catalog=uniquenamehere to your connection string.
Though he says "... where 'uniquenamehere' is some name for your project.", try replacing uniquenamehere with the actual name of the database where the table exists.
the file is a .mdf file so it is a mssql file
my guess would be that as you stated you are using mysql the connection string has to be a tad different and therefore the Dataset can't connect to Mysql
Try adding User Instance=True; to the connection string.

How to delete a table in postgresql

There is a postgresql installation on my server that worked fine so far. However now there is a single table (all other tables work fine) which I cannot open through pgadmin3 or drop.
I've tried restarting the server. Didn't help. I also tried dropping the table with DROP TABLE from the command line on the server. It's just stuck. I've executed the command and it has been just hanging in the console for the past hour.
I don't know what to do. Is there a file I could erase in the data directory perhaps?
Most probably explanation: some other open transaction is holding an exclusive lock on the table.
You are using pgAdmin, so you can check with Tools -> Server Status. The activity pane lists all current connections. For instance, there is one (or more) listings for every open SQL window. Look for long running connections.
You can also try to issue a DROP TABLE and check this list. With any luck you'll see what blocks it. Once you have identified the troublemaker and made sure, it's not needed, you might be able to kill the process. Might be vacuuming gone haywire because of bad settings ..
That, or something is seriously broken.
You could try taking a dump of the database and see if that works? Also have a look at the http://www.postgresql.org/docs/9.1/static/runtime-config-logging.html#GUC-CLIENT-MIN-MESSAGES and log_min_messages options. Change that to debug and see what is happening when you try to drop the table.
In Case of Windows Users. Try restarting Postgresql by follwowing these steps: Start -> Run -> (then type in:) services.msc. Select Local postgresql Server and then press "Restart." Now, go ahead and try deleting the database or the table you wanted to delete (Via pgAdmin). Hope it helps.

SQLITE3: Creating database from command line takes forever

I run a service that creates many SQLITE3 databases and later on removes them again, they live for about a day maybe. They all have the same schema and start empty.
I use this to create a new blank SQLITE3 database:
sqlite3 newDatabase.db < myschema.sql
The myschema.sql file contains three table schemas or so, nothing fancy, no data. When I execute the above command on my rather fast, dedicated linux server, it takes up to 5 minutes to complete. There's processes running in the background, like a couple of PHP scripts using CPU time, but everything else is fast, like other commands or inserting data into the DB later on. It's just the creation that takes forever.
This is so weird, I have absolutely no idea what's wrong here. So my only resort right now is to create a blank.db once, and just make a fresh copy from that rather than importing from a SQL schema.
Any idea what I messed up? I initially thought the noatime settings on linux were messing with it, but no, disabling didn't change anything.
Willing to provide any configuration/data you need.
Edit:
This is what strace hangs at:
12:29:45.460852 fcntl(3, F_SETLK, {type=F_WRLCK, whence=SEEK_SET, start=1073741824, len=1}) = 0
12:29:45.460965 fcntl(3, F_SETLK, {type=F_WRLCK, whence=SEEK_SET, start=1073741826, len=510}) = 0
12:29:45.461079 lseek(4, 512, SEEK_SET) = 512
12:29:45.461550 read(4, "", 8) = 0
12:29:45.462639 fdatasync(4
A possibility is to use the strace command to see what's happens :
strace -f -s 1000 -tt sqlite3 newDatabase.db < myschema.sql
If it hangs somewhere, you will see.
Is your schema is HUGE ?
NOTE
in case of questioning about too high I/O disk, try the command iotop -oPa, you will see "who's" put the mess in your system
Alright I think I figured out the issue.
The server was running a couple of PHP scripts in the background that seemed to somewhat behave with CPU load, it often spiked at 100%, but all other commands worked fine mostly except installing things through APT-GET and installing new SQLITE3 databases out of a schema.
What probably caused the problem was the heavy disk access (IO operations). I re-installed APC, upgraded to a new version, figured out it was disabled for CLI (which is a default) but enabled it since I have long-running scripts, also added a few usleep(100) here and there.
I stopped every single PHP command, basically killed every program not required. Checked system usage through MYSQL Workbench, it seemed still very high until I realized that this is an average value. If you wait another 10 minutes, it will average out, which in my case was close to 0% LOAD. Perfect.
Then I restarted the scripts and it seems to be holding things down now.
I tried the SQLITE3 command mentioned above and it worked instantly, as expected.
So, simple cause: Not only high CPU load, but also HEAVY IO, disk access.