Attack Database using C# (SQLServer)
- Tự động attack CSDL khi khởi động phần mềm :
using System;
using System.Collections.Generic;
using System.Linq;
using System.Windows.Forms;
using HospitalManager.Business_Logic_Layer;
using Microsoft.SqlServer.Management.Smo;
using Microsoft.SqlServer.Management.Common;
using System.Collections.Specialized;
namespace HospitalManager
{
static class Program
{
static void Main()
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
try
{
//check database exists
String DatabaseName = "Hospital";
Server SqlServer = new Server(@".\SQLEXPRESS");
ServerConnection SqlServerConnection = SqlServer.ConnectionContext;
SqlServerConnection.LoginSecure = true;
SqlServerConnection.DatabaseName = "master";
if (SqlServer.Databases[DatabaseName] == null)
{
Database NewDatabase = new Database(SqlServer, DatabaseName);
FileGroup DatabaseFileGroup = new FileGroup(NewDatabase, "PRIMARY");
NewDatabase.FileGroups.Add(DatabaseFileGroup);
DataFile DatabaseDataFile = new DataFile(DatabaseFileGroup, DatabaseName);
DatabaseFileGroup.Files.Add(DatabaseDataFile);
DatabaseDataFile.FileName = Application.StartupPath + "\\" + DatabaseName + ".mdf";
LogFile DatabaseLogFile = new LogFile(NewDatabase, DatabaseName + "_log");
NewDatabase.LogFiles.Add(DatabaseLogFile);
DatabaseLogFile.FileName = Application.StartupPath + "\\" + DatabaseName + "_log.ldf";
StringCollection DatabaseFilesCollection = new StringCollection();
DatabaseFilesCollection.Add(DatabaseDataFile.FileName);
DatabaseFilesCollection.Add(DatabaseLogFile.FileName);
SqlServer.AttachDatabase(DatabaseName, DatabaseFilesCollection);
}
}
catch
{
MessageBox.Show("Co loi khi thiet lap co so du lieu", "Hospital Manager");
}
Application.Run(new Presentation_Layer.frmHospitalManager());
}
}
}
Tags: CSharp, SQL
Bài viết liên quan:
Share your views...
0 Respones to "Attack Database using C# (SQLServer)"
Đăng nhận xét