I had to rename a database recently and googled the result. There are many usual resources and with ready-to-use examples. I will record them here for my own references and at mean time, I will add more details on what the commands do.
With renaming database, we need to set the database to single user mode first. Once the name is changed, we will set the multi-user mode back to the database.
This script does just that for SQL Server 2000:
ALTER DATABASE orig_db_name SET SINGLE_USER WITH ROLLBACK IMMEDIATE
EXEC sp_renamedb 'orig_db_name', 'new_db_name'
ALTER DATABASE new_db_name SET MULTI_USER
SQL Server 2005+ should use this slightly different version:
ALTER DATABASE orig_db_name SET SINGLE_USER WITH ROLLBACK IMMEDIATE
ALTER DATABASE orig_db_name MODIFY NAME = new_db_name
ALTER DATABASE new_db_name SET MULTI_USER
First of all, I would like talk about the single user mode. If this mode is on, this means only one user can connect to the SQL server at one time. It will enable the user to change any server configuration or recover a damaged master database or other system database. Single user mode can also be set via the main plan configured on the SQL instance with Check Database Integrity task in the plan along with the “attempt to repair minor problems” option enabled. This will put the database in single user mode before executing CHECKDB.
However, sometimes, it is also can be a pain as if the connection is overtaken by another user, the actual user will not be able to logon and we need to seek other solution to break in e.g., kill the other process first, etc.
Meanwhile, the single user mode can also be stuck and you may not able to set the multi-user mode back on. See this post for a good example http://blogs.msdn.com/b/dfurman/archive/2012/01/20/getting-out-of-single-user-mode.aspx.
The next is the WITH ROLLBACK IMMEDIATE clause. It is a clause that we do not use usually but it is quite helpful. This simply means that if you would like to roll back immediately or not. There are another two options here.
Option 1: WITH ROLLBACK AFTER integer [SECONDS] – this means the transaction will still roll back if it encounters problem but within the seconds specified.
Option 2: WITH NO_WAIT – it simply means the transaction will not wait and if it encounters problem it will fail immediate without wait for roll back or commit.
Showing posts with label How-to. Show all posts
Showing posts with label How-to. Show all posts
Tuesday, 1 April 2014
Monday, 12 August 2013
How to delete the Windows IconCache.db file
Recently, I have experienced a problem that my application shortcut icon is not displayed anymore after an upgrade. Later, we fixed the issue by deleting the Windows IconCache.db file and it involves in stoping and starting of the Windows Explorer. The steps to delete the IconCache.db file is listed below and all operations are done via Windows Command Line:
Step 1: open command line
type cmd in search programs and files at Start menu
Step 2: Command to kill the current Windows Explorer (i.e., the desktop will become empty and without task bar afterward)
taskkill /IM explorer.exe /F
Step 3: Go to location of IconCache.db file
cd C:\Users\Admin\AppData\Local
Step 4: Command to view the IconCache.db file (it is hidden)
dir /A:H
Step 5: Delete the IconCache.db file
del IconCache.db
Step 6: Restart Windows Explorer
explorer
Step 1: open command line
type cmd in search programs and files at Start menu
Step 2: Command to kill the current Windows Explorer (i.e., the desktop will become empty and without task bar afterward)
taskkill /IM explorer.exe /F
Step 3: Go to location of IconCache.db file
cd C:\Users\Admin\AppData\Local
Step 4: Command to view the IconCache.db file (it is hidden)
dir /A:H
Step 5: Delete the IconCache.db file
del IconCache.db
Step 6: Restart Windows Explorer
explorer
Monday, 5 November 2007
How do I convert a string to a byte array and vica-versa in VB.NET and C#?
Convert String to Byte[]
' VB.NET to convert a string to a byte array
Public Shared Function StrToByteArray(str As String) As Byte()
Dim encoding As New System.Text.ASCIIEncoding()
Return encoding.GetBytes(str)
End Function 'StrToByteArray
// C# to convert a string to a byte array.
public static byte[] StrToByteArray(string str){
System.Text.ASCIIEncoding encoding=new System.Text.ASCIIEncoding();
return encoding.GetBytes(str);
}
Convert Byte[] to String
' VB.NET to convert a byte array to a string:
Dim dBytes As Byte() = ...Dim str As StringDim
enc As New System.Text.ASCIIEncoding()
str = enc.GetString(dBytes)
// C# to convert a byte array to a string.
byte [] dBytes = ...string str;
System.Text.ASCIIEncoding enc = new System.Text.ASCIIEncoding();
str = enc.GetString(dBytes);
Ref.: http://www.chilkatsoft.com/faq/DotNetStrToBytes.html
' VB.NET to convert a string to a byte array
Public Shared Function StrToByteArray(str As String) As Byte()
Dim encoding As New System.Text.ASCIIEncoding()
Return encoding.GetBytes(str)
End Function 'StrToByteArray
// C# to convert a string to a byte array.
public static byte[] StrToByteArray(string str){
System.Text.ASCIIEncoding encoding=new System.Text.ASCIIEncoding();
return encoding.GetBytes(str);
}
Convert Byte[] to String
' VB.NET to convert a byte array to a string:
Dim dBytes As Byte() = ...Dim str As StringDim
enc As New System.Text.ASCIIEncoding()
str = enc.GetString(dBytes)
// C# to convert a byte array to a string.
byte [] dBytes = ...string str;
System.Text.ASCIIEncoding enc = new System.Text.ASCIIEncoding();
str = enc.GetString(dBytes);
Ref.: http://www.chilkatsoft.com/faq/DotNetStrToBytes.html
Subscribe to:
Posts (Atom)