Database Server Disk Memory is Full - sql-server

I am using SQL Server for my web application. How will I know that an insert query failed because the database server memory disk is already full

The error code you will get back will indicate that the disk is full: 1105 (primary filegroup full) or 9902 (log file full)

You can simulate this by disabling the auto-grow feature on the database (It's a checkbox in the database properties on the file tab) and filling up the database. The error will be the same.
ALTER DATABASE YourDatabase
MODIFY FILE (name='YourFile' MAXSIZE=50MB);

if you want to find you memory usage
exec sp_spaceused
This will give you how much memory you are used for particular database

Check the error code you get back from SQL Server when you try to insert into the database.
With that error given back you can then decide what to do. (e.g. Try to insert again,
Try to free up some memory on the server) Also if you havent already, place your Insert statement inside a Transaction so that you can rollback if an error occurs.

I suppose you can believe that if the disk is full the SQL server will return the error code :).
You can make your testing code think it is communicating with the SQL server but instead it will talk to some fake object of yours that will respond with the error codes you want to test.
There are frameworks that can help you. One of them is Rhino Mocks you can download from http://ayende.com

Related

SQL Server Backups

I am having some issues with database backups.
My database is in simple recovery mode and database backup occurs every night. We some times getting backup job failed and throwing the error as below.
ERROR:
The operating system returned the error '112(failed to retrieve text for this error. Reason: 15105) while attempting 'SetEndOfFile' on \backups\sqlbackups\finename
Possible failure reasons: Problems with the query, "ResultSet" property not set correctly, parameters not set correctly, or connection not established correctly.
Problems with the query / Property not set correctly / Parameters not set correctly: this is running from past 2 years.
I am still unsure why this happens some times.
If anyone having the same issue and figured out the possible reason, please discuss
Server info: SQL Server 2008 R2, Standard
Database info: simple recovery mode and is acting as a publisher with size 1.4TB
Thanks in advance
It seems you haven't enough space on your destination place. Make sure that there is enough free space on your drive and try again. If you use a third-party tool to backup your databases set "Auto-delete" option to delete your old backups.

Syslog-ng not logging to empty sqlite database

We're developing an application based on Yocto, distro Poky 1.7, and now we've to implement the logger, so we have installed the one already provided by our meta-oe layer:
Syslog-ng 3.5.4.1
libdbi 0.8.4.1
libdbi-drivers 0.8.3
Installation has been done without any problems and Syslog-ng can run correctly, except that it doesn't write to an existing sqlite database.
In the syslog-ng.conf file there is just one source, default unix stream socket /dev/log, and one destination, a local sqlite database (of just 4 columns). A simple program that writes 10 logs with the use of the C API 'syslog()' is used for test purposes.
If the database already exists, empty or not, when running the demo program, no log message is written into the database;
If the database doesn't exist, Syslog-ng creates it and is able to write log message until the board is rebooted. After that, we fall back into condition one, so no more log message could be save into the db.
After some days spent on this issue, I've found that this behaviour could be due to this sql statement (in function afsql_dd_validate_table(...) in afsql.c ):
SELECT * FROM tableName WHERE 0=1
I know that this is a useful statement to check existance of the table called 'tableName', and the WHERE 0=1 a always false condition to avoid to parse the whole table.
Enabling Syslog-ng debug it seems that previous statement doesn't return any information about columns, so Syslog-ng think they don't exist and try adding them, causing an error since they already exist. That's why it doesn't write anything to the database.
Modifying the sql query with this one
SELECT * FROM tableName
I'm still unable to write any log message to the database if it is empty, but now it's possible to make all working in the right way if when the database is created a dummy record (row) is added.
But this should not be the right way to work, has anyone faced thi issue and found a solution on how to make Syslog-ng logging with empty sqlite database?
Many thanks to everybody
Regards
Andrea

Crystal Reports creating temporary table with SQL Server

I'm using Crystal Reports 2008 with SQL Server 2014.
I read on the internet that it was possible to create a temporary table with Crystal Reports. This link says that, one of many examples -> Click here
Yet when I go to the database expert, create a new command and enter the following DDL
CREATE TABLE #temp_test (col1 VARCHAR(5))
I get this error
Translation:
database connector error : 'No error message from server'
Yet, when I'm doing that with SQL Server on my database, everything is fine.
Have you managed to do it? If yes, how?
It sounds like an urban legend to me but I might be wrong...
Cheers
When you create a "Command" table in Crystal, you're giving Crystal a set of text to send to the SQL server, and Crystal expects a data set in return. Everything in between is done on the SQL server. Crystal checks the command by sending it to the SQL server when you enter it to see if it works.
Given that, your temp table is actually created on the SQL server. Also, when you create a temp table, it is deleted after the command is finished running.
As a result, if you use only this code, the SQL server will create the table, but there is no data set to return. It succeeds, so doesn't return an error, but also doesn't return data, hence the message: "No error message from server".
For your next step, I would suggest using code like this:
CREATE TABLE #temp_test (col1 VARCHAR(5))
SELECT * FROM #temp_test
This will create an empty data set to return to Crystal, so that it's getting the response it needs. I say this so that you don't think anything is wrong when you don't see anything. You'll need to insert data into the temp table in order to get it from the select statement for visual confirmation.
I would also suggest that you don't use a temp table unless you determine that you do or will actually need one within the scope of the command. For example, you may need one to increase performance on a particularly complex query or CTE, so it might increase performance to use a temp table. But I would create that query first and worry about optimization after I have at least some of it developed.

SQL Server Express edition - read-only database?

I'm having a very strange problem with a fresh install I have of SQL Server 2008 Express edition (yeah it's a bit old now, but whatever). When I connect via SQL Server Management Studio, I can both read and edit data (update or insert), but when I connect via my web application's data access layer, which uses SqlConnection and SqlCommand to try and update and insert data in tables, no changes occur in the database. The strange thing is that the code runs as if no error had occurred though; no exceptions are thrown, and my update statement causes SqlCommand.ExecuteNonQuery to return 1, indicating that supposedly 1 row has been updated. However, it hasn't. The application can, however, read data from the database via select statements.
Does anyone have any idea what's going on here? I even tried tracing SQL Server using ExpressProfiler, and its output seemed to indicate that the update should have occurred:
exec sp_executesql N'UPDATE Match SET TicketsSold=#ticketsSold WHERE MatchId=#matchId',N'#matchId int,#ticketsSold int',#matchId=1,#ticketsSold=1234
go
Yet TicketsSold stays at the same value (123) it was at before, and does not update to 1234. Is there some kind of "silent" read-only mode SQL Server 2008 Express could be running in? I'm baffled as to why the database isn't being updated.
By the way, this is a proper SQL Server database I created in SSMS, not some attached MDF file that resides in the same directory as my web application. The database is not set to "read-only" in database options, and I'm pretty sure that the user that the web application is logging in as has read/write permission on the MDF file; it is logging in as the same user I am logging in as using SSMS - with integrated Windows security - and I am able to update/insert as that user via SSMS.
Thanks to shf301 in the comments - I was creating a transaction but forgetting to call .Commit before the end of the using block. :-D I put that in and now it works.

SQL Server error cannot open database

Helo fellow, sorry for being annoying u again =P.
Today a got a mission in the job... ¬¬'
Our system works integrated to SQL Server. There were two databases. The main one, and another "responsible" for doing some data integration stuffs...
One day, the boss decided not to use the second database anymore, and ordered the team to create a fix application that unlinked these databases. But in one of our clients the SQL Server is givin' an error message:
-[Microsoft][ODBC SQL Server Driver][SQL Server] Database 'XXX' cannot be onpened due to inaccessible files or insufficient memory or disk space.
I've checked the disk space and it's fine. The memory amount is ok too. And the database files, doesn't exist anymore in the SQL data folder (like we expected and the boss desired).
This error could be expected if the were references in the sql server, but the database is not atached anymore, the table 'sysdatabases' in the master database doesn't references the database...
Someone can give a clue? I'm previously thankful for any help. =)
Sounds to me like the client is running an old version of the code which is still trying to connect to the database that's been unlinked.

Resources