This C# program demonstrates how to rename an SQL database for Microsoft SQL in C#.
using System;
using System.Data.SqlClient;
namespace RenameDatabase {
class Program {
static void Main(string[] args) {
Console.WriteLine(RenameDatabase("XoaX", "XoaXnet"));
}
public static string RenameDatabase(string sDatabase, string sNewName) {
// The using block ensures that the connection is closed when it exits this block.
using (SqlConnection qConnection = new SqlConnection(
@"Server=LAPTOP-FHJLCP14\SQLEXPRESS;Trusted_Connection=True;")) {
SqlCommand qCommand = qConnection.CreateCommand();
qCommand.CommandText = "ALTER DATABASE " + sDatabase+ " MODIFY NAME = " + sNewName;
qCommand.Connection.Open();
return qCommand.ExecuteNonQuery().ToString();
}
}
}
}
-1 Press any key to continue . . .
© 20072025 XoaX.net LLC. All rights reserved.