A useful tool set for working with DBF files

by Shawn 30. November 2009 10:25

CDBF from WhiteTown

cdbfwgui.zip (2.29 mb)

DBFViewer from cooolutils

DBFViewer.exe (1.62 mb)

And a nice shell extension for getting quick information about a DBF file

cdbfinfo.zip (341.77 kb)

Tags:

Development

Update to RDP Gadget

by Shawn 29. November 2009 07:33

I added support for more screen resolutions, fixed the connect to console bug on windows 7 and cleaned up some of the javascript code .

fxRDP.gadget (359.08 kb)

Tags:

Windows 7

A few helpful articles on SharePoint 2010 Beta 2

by Shawn 23. November 2009 08:34

Tags:

Social Networking

How to Alter a SQL Server Database as Single User Mode and as Multi User Mode

by Shawn 20. November 2009 05:51

Original Link: http://www.kodyaz.com/articles/alter-single-user-multi-user-mode.aspx

You can use the SQL Server Enterprise Manager for SQL Server 2000 to set a database to a single user mode or to multi user mode. Similarly, SQL Server Management Studio can be used for SQL Server 2005 for changing a database to single user mode or to multi user mode. Also you can alter the database access mode by using sql commands like ALTER DATABASE and sp_dboption.

 

ALTER DATABASE [Works] SET MULTI_USER WITH NO_WAIT

ALTER DATABASE [Works] SET SINGLE_USER WITH NO_WAIT

or

EXEC sp_dboption 'Works', 'single user', 'false'

EXEC sp_dboption 'Works', 'single user', 'true'

To alter the database state to restrict the access to the single user mode, first open the Microsoft SQL Server Management Studio, and connect to a SQL Server instance. Open the list of available databases belonging to the related instance in the Object Explorer window. Right click on the sql server database that you want to set its mode to single user and select Properties in the context menu.

When you click properties menu item, the following Database Properties screen will be displayed for the selected database. I used database named Works for samples used for the article.

restrict access

Select the Options page from the list in the left side of the screen. If you scroll down the options list for State options, you will see Restrict Access database options with three options listed in the combo box.

Restrict Access modes : Multiple, Single and Restricted modes.

 

If you select Single mode and click the OK button, you can either alter the database access mode to single user successfully or you will fail to change the access mode because of existence of active open connections to the Works database. The Management Studio IDE will prompt you to close all other connections to the related database for a successfull alter database option process.

open connections

To change the database properties, SQL Server must close all other connections to the database. Are you sure you want to change the properties and close all other connections?
 

After the alter command runs successfully, the database Works will be displayed as shown in the Object Explorer window.
single-user

 

If an active connection exists other than the Management Studio, and you click the database Works within the SQL Server Management Studio, the following warning message will be displayed:


database-is-not-accessible

The database Works is not accessible. (ObjectExplorer)

 

If you right click on the database Works, the following error message will be displayed.

database-is-already-open

Database 'Works' is already open and can only have one user at a time. (Microsoft SQL Server, Error: 924)

 

After a database is altered as single user mode, it can be altered again back to multi user mode by running the below sql command.

ALTER DATABASE [Works] SET MULTI_USER WITH NO_WAIT

But if this command is run from a connection that is not the only active connection to the related database, the command will fail with the following message:

Msg 5064, Level 16, State 1, Line 1
Changes to the state or options of database 'Works' cannot be made at this time. The database is in single-user mode, and a user is currently connected to it.
Msg 5069, Level 16, State 1, Line 1
ALTER DATABASE statement failed.

 

 

In a case that you want to alter the database access mode from single user mode to multi user mode or from multi user mode to single user mode, you may have to kill all the active open connections to the database.

In such a case, you have to find all the open connections and run "Kill @spid" command to close all the connections.

For a list of open connections for a specific database you can run a similar command as below :

select spid from master..sysprocesses where dbid = db_id('Works') and spid <> @@spid

The second part of the task will be closing the open connections with the Kill command. This can be achived by running kill commands within a cursor or creating a dynamic sql command which kills the active connections to the related database.

Let's code the closing open connections using a t-sql cursor:

DECLARE @DatabaseName nvarchar(50)
DECLARE @SPId int

SET @DatabaseName = N'Works'

DECLARE my_cursor CURSOR FAST_FORWARD FOR
SELECT SPId FROM MASTER..SysProcesses WHERE DBId = DB_ID(@DatabaseName) AND SPId <> @@SPId

OPEN my_cursor

FETCH NEXT FROM my_cursor INTO @SPId

WHILE @@FETCH_STATUS = 0
BEGIN
KILL @SPId

FETCH NEXT FROM my_cursor INTO @SPId
END

CLOSE my_cursor
DEALLOCATE my_cursor

 

After all connections are closed except the currently running prcess (@@spid) if we are trying to alter the access mode of the database that we're in from multi user mode to single user mode, we can now run the ALTER DATABASE command for single user mode or multi user mode.

ALTER DATABASE [Works] SET MULTI_USER WITH NO_WAIT

or

ALTER DATABASE [Works] SET SINGLE_USER WITH NO_WAIT

 

You can also use the following sp_dboption sql commands to alter the database option for single user. If you set the "single user" database option to "true", this is same as altering the database as "SINGLE_USER" with ALTER DATABASE statement.


USE master
GO
EXEC sp_dboption 'Works', 'single user', 'false';


If you run the below sp_dboption command which sets the "single user" to "false", this is same as altering the database as "MULTI_USER" with ALTER DATABASE statement.


USE master
GO
EXEC sp_dboption 'Works', 'single user', 'true';

 

The main difference between sp_dboption and ALTER DATABASE commands is that, sp_dboption will not be supported with further releases of SQL SERVER after SQL SERVER 2005.

Tags:

Development

How to make an AJAX call from inside Silverlight

by Shawn 17. November 2009 08:05

Here is a little snippet that will let you make a remote AJAX call from inside Silverlight - the only catch is that you will get a "security warning" dialog for making a crossdomain call

ScriptObjectCollection scriptCollection = HtmlPage.Document.GetElementsByTagName("head");
HtmlElement head = (HtmlElement)scriptCollection[0];

HtmlElement script = HtmlPage.Document.GetElementById("dataAccess_js");
if (script == null)
{
	script = HtmlPage.Document.CreateElement("script");
	script.SetAttribute("type", "text/javascript");
	script.Id = "dataAccess_js";

	StringBuilder sbScript = new StringBuilder();

	sbScript.AppendLine("function createXMLHttpRequest() { var httprequest = false; if (window.XMLHttpRequest) { httprequest = new XMLHttpRequest(); if (httprequest.overrideMimeType) httprequest.overrideMimeType(\"text/xml\"); } else if (window.ActiveXObject) {  try { httprequest = new ActiveXObject(\"Msxml2.XMLHTTP\"); } catch (e) { try { httprequest = new ActiveXObject(\"Microsoft.XMLHTTP\"); } catch (e) { } } } return httprequest; }");
	sbScript.AppendLine("function retrieveContent(url) { var request = createXMLHttpRequest(); request.open(\"GET\", url, false); request.send(null); if (request.status == 200) { var text = request.responseText; return text; } else { alert(\"Error loading \" + url); } }");

	script.SetProperty("text", sbScript);

	head.AppendChild(script);
}

var result = HtmlPage.Window.Invoke("retrieveContent", sURL);

Tags:

Scripting

Powered by BlogEngine.NET 2.5.0.6
Theme by Mads Kristensen | Modified by Mooglegiant

About the author

As an individual with a passion for technology and knolwedge I have long enjoyed being part of the computer industry as both a systems architect and infrastructure engineering.  This blog is way for me to share some thoughts. ideas, and ponderings on all of these things.

Calendar

<<  February 2012  >>
MoTuWeThFrSaSu
303112345
6789101112
13141516171819
20212223242526
2728291234
567891011

View posts in large calendar

Calendar Of Posts