08.23.06
Posted in Microsoft Sql server at 9:34 am by
If you ever find yourself in a situation where you need to rename a SQL Server database you could use the following 3 statements to do the job:
-- Make sure that you are the only user accessing the db
EXEC sp_dboption 'old name', 'Single User', 'TRUE'
-- Rename the db
EXEC sp_renamedb 'old name', 'new name'
-- Allow other users to login again
EXEC sp_dboption 'new name', 'Single User', 'FALSE'
Permalink
08.11.06
Posted in TSQL, Visual Basic 6 at 9:11 pm by
For some reason you would like to know how many records where affected by your sql statement called from visual basic 6. But you have no clue how to do it.
This is how you do it.
When you do a query in sql server then you can see how many rows where affected by it, because sql server fills up the @@rowcount variable.
Code:
delete from customer where name like 'A%'
print @@rowcount
If you want to return this result to a result set you can do the following:
Code:
delete from customer where name like 'A%'
select @@rowcount as affected
Then in visual basic 6:
dim newrs as ADODB.Recordset
Set newrs = rs.NextRecordset
msgbox newrs.Fields("affected")
Permalink
08.07.06
Posted in OpenGL at 9:51 pm by
Switching between windowed mode and fullscreen is usually done by creating a new window just to change the window style. There is however an easier way to change the style without creating a new window.
//Remove the window decoration.
LONG dwStyle = GetWindowLong(hWnd, GWL_STYLE) ^ WS_OVERLAPPEDWINDOW;
//Add back the window decoration.
LONG dwStyle = GetWindowLong(hWnd, GWL_STYLE) | WS_OVERLAPPEDWINDOW;
//Set the selected style.
SetWindowLong(hWnd, GWL_STYLE, dwStyle);
//Redraw your window.
SetWindowPos(hWnd, HWND_TOP, x, y, width, height, SWP_FRAMECHANGED);
Permalink
07.29.06
Posted in DBA, Microsoft Sql server at 2:12 am by
Sometimes you have to restore a backup file for a database with replication. This is how you do it.
Preparing the restore
- Copy the backed up database file to your database server. Then disconnect everyone from the database.
- In the windows start menu go to run and fill in: Services.msc and Press ok
- Find the Distributed Transaction Coordinator (msdtc.exe) and stop this service. (you do this by right clicking on it and selecting stop)
- Stop the sql server agent service
Restoring the database
- In Microsoft sql server management studio you connect to the server which holds the database you want to restore. Then you open the node databases and right click Restore/Database…In the Restore database window, you see a section Source for restore. There you select from device and you browse for the back up file you have on your server. After selecting it you will see a new line in the grid below. You select the checkbox restore.
- On the left side of the window you select the Options page.
- Select the option Overwrite the existing database & Preserve the replication settings.
- As recover state you leave the database ready to use by rolling back uncommitted transactions. Additional transaction logs cannot be restored(Restore with recovery)
During the restore
Just wait will the back up is being restored.
After the restore
When the restore is finished you can turn back on the services you stopped.
Permalink
07.27.06
Posted in Microsoft Sql server, TSQL at 10:57 pm by
One of the common shortcomings of the novice sql guru is the lack of knowledge about transactions.
What is a transaction?
A transaction consits off several statements which are executed as a single unit. Either all the statements are done or they all fail. You’ll need this functionality in situations which require atomicity. For instance you are coding for a bank and your code has to transfer money from one account to another.
Sample without transactions:
UPDATE accounts SET money = money - 200 WHERE id = 1
–> the server crashes here
UPDATE accounts SET money = money + 200 WHERE id = 2
Now the first guy has lost his money and the second guy never received the money.
Sample with transactions:
BEGIN TRANSACTION
UPDATE accounts SET money = money - 200 WHERE id = 1
–> the server crashes here
UPDATE accounts SET money = money + 200 WHERE id = 2
COMMIT
Now when the server is recovered the first sql statement has never happend so the first guy still has all his money.
Permalink
Next entries »