//E.g SqlExpress
1.Click the Windows Start button, and then click Run. The Run dialog box appears.
2.Type Services.msc into the Open field, and then click OK. The Services
panel appears:
3.Right-click the SQL Server (SqlEx[ress) service, and then click Properties from the shortcut menu. The SQL Server (SqlExpress) Properties (Local Computer) dialog box appears:
4.On the Log On tab, select Local System account for the Log on as option.
5.Press Apply and then press OK on the dialog box that appears.
6.Click on the General tab and then press Stop the stop the service, and Start to restart the SqlExpress service.
7.Press OK and close the services Console.
8.Launch SqlExpress and attempt to now restore the database.
http://www.prpraveen.blogspot.com
Saturday, October 24, 2009
Monday, October 19, 2009
Problem while Saving modified .bmp file A generic error occurred in GDI+. C# .net By Praveen P.R
//Problem while Saving modified .bmp file
//A generic error occurred in GDI+.
//Do the following
//some function...... inside it.....
try
{
System.GC.Collect();//imp
System.GC.WaitForPendingFinalizers();//imp
if (System.IO.File.Exists(Application.StartupPath + @"\Alpha100.bmp"))
{
System.IO.File.Delete(Application.StartupPath + @"\Alpha100.bmp");
}
myBitmap.Save(Application.StartupPath + @"\Alpha100.bmp");
}
catch (Exception ex)
{
MessageBox.Show(ex.ToString());
}
//A generic error occurred in GDI+.
//Do the following
//some function...... inside it.....
try
{
System.GC.Collect();//imp
System.GC.WaitForPendingFinalizers();//imp
if (System.IO.File.Exists(Application.StartupPath + @"\Alpha100.bmp"))
{
System.IO.File.Delete(Application.StartupPath + @"\Alpha100.bmp");
}
myBitmap.Save(Application.StartupPath + @"\Alpha100.bmp");
}
catch (Exception ex)
{
MessageBox.Show(ex.ToString());
}
Posted by
Praveen P.R
Steps to Create a Crystal Report based on an XML schema (XSD) file.
1.Create Dataset with.(e.g Select * from anytable)
Note:-Basic knowledge of C# required
2.e.g Dataset ds;
3.Then write the following code e.g ds.WriteXmlSchema("RptDailyAll.xsd");
4.Above code will genrate "RptDailyAll.xsd" file in the current directory
5.Now open a new crystall report and follow the steps as seen in images
Note:-Basic knowledge of C# required
2.e.g Dataset ds;
3.Then write the following code e.g ds.WriteXmlSchema("RptDailyAll.xsd");
4.Above code will genrate "RptDailyAll.xsd" file in the current directory
5.Now open a new crystall report and follow the steps as seen in images
Posted by
Praveen P.R
Tuesday, October 13, 2009
Steps VSS Visual Source Safe .net By Praveen P.R
Step to Manage VSS
1.Create folder for VSS this will act as Server Database.
2.Make this folder shared .So to access for client System.
2.Now take-->Microsoft Visual SourceSafe Administration(Programs->Microsoft Visual SourceSafe-->)
3 Create new database
Menu File-->New DataBase...
1.Create folder for VSS this will act as Server Database.
2.Make this folder shared .So to access for client System.
2.Now take-->Microsoft Visual SourceSafe Administration(Programs->Microsoft Visual SourceSafe-->)
3 Create new database
Menu File-->New DataBase...
Posted by
Praveen P.R
Monday, October 12, 2009
Install .bak file at first run / installation C# By Praveen P.R
//This is to show how to restore your .bak file (SQL Express) when your first run the application
1. Add this code in your app.config file
add key="ConnectionString" value="Data Source=.\sqlexpress;Initial Catalog=Transactions;Integrated Security=True"
add key="ConnectionStringM" value="Data Source=.\sqlexpress;Initial Catalog=master;Integrated Security=True"
using connectionstring added above
using System.Configuration; this.connectionString = ConfigurationSettings.AppSettings["ConnectionString"];
2. Above code is to connect to sql express default database
3.Now when your application runs for the first time check the name of the database if it exists in sql express
with the above connection string.
4.for eg.
CheckDBExist("Transactions");//database name
5.
private bool CheckDBExist(string dbName)
{
BLLTransaction bllTransaction = new BLLTransaction(classGlobal.connectionStringM);
DataSet dsChkDBExist;
dsChkDBExist = bllTransaction.Select("select * from sys.databases where name = '" + dbName + "'");
if (dsChkDBExist.Tables[0].Rows.Count == 0)
{
DialogResult result = MessageBox.Show("Database not found.\nDo you want to Restore Database?", "Restore Database", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
if (result == DialogResult.Yes)
{
try
{
Server mServer = new Server(@".\sqlexpress");
//mServer.KillAllProcesses("Transactions");
//mServer.DetachDatabase("Transactions", true);
//Application.StartupPath.Replace only needed at project devlopment
File.Move(Application.StartupPath.Replace("bin\\Debug", "") + @"TranDB\Transactions.mdf", @"C:\Program Files\Microsoft SQL Server\MSSQL.1\MSSQL\data\Transactions.mdf");
File.Move(Application.StartupPath.Replace("bin\\Debug", "") + @"TranDB\Transactions_log.ldf", @"C:\Program Files\Microsoft SQL Server\MSSQL.1\MSSQL\data\Transactions_log.ldf");
//File.Move(Application.StartupPath + @"TranDB\Transactions.mdf", @"C:\Program Files\Microsoft SQL Server\MSSQL.1\MSSQL\data\Transactions.mdf");
//File.Move(Application.StartupPath + @"TranDB\Transactions_log.ldf", @"C:\Program Files\Microsoft SQL Server\MSSQL.1\MSSQL\data\Transactions_log.ldf");
StringCollection files = new StringCollection();
files.Add(@"C:\Program Files\Microsoft SQL Server\MSSQL.1\MSSQL\data\Transactions.mdf");
files.Add(@"C:\Program Files\Microsoft SQL Server\MSSQL.1\MSSQL\data\Transactions_log.ldf");
mServer.AttachDatabase("Transactions", files, AttachOptions.None);
}
catch (Exception ex)
{
MessageBox.Show(ex.ToString());
}
}
}
return true;
}
6.The above code have my bll class which i use for connection above code to give some idea ;)
7.getSqlExpressPath() //to get sqlexpress path
private string getSqlExpressPath()
{
string path = "";
using (RegistryKey sqlServerKey = Registry.LocalMachine.OpenSubKey(@"SOFTWARE\Microsoft\Microsoft SQL Server"))
{
foreach (string subKeyName in sqlServerKey.GetSubKeyNames())
{
if (subKeyName.StartsWith("MSSQL."))
{
using (RegistryKey instanceKey = sqlServerKey.OpenSubKey(subKeyName))
{
string instanceName = instanceKey.GetValue("").ToString();
if (instanceName == "SQLEXPRESS")//say
{
path = instanceKey.OpenSubKey(@"Setup").GetValue("SQLBinRoot").ToString();
path = Path.Combine(path, "sqlserver.exe");
}
}
}
}
}
return path;
}
http://www.prpraveen.blogspot.com
1. Add this code in your app.config file
3.Now when your application runs for the first time check the name of the database if it exists in sql express
with the above connection string.
4.for eg.
CheckDBExist("Transactions");//database name
5.
private bool CheckDBExist(string dbName)
{
BLLTransaction bllTransaction = new BLLTransaction(classGlobal.connectionStringM);
DataSet dsChkDBExist;
dsChkDBExist = bllTransaction.Select("select * from sys.databases where name = '" + dbName + "'");
if (dsChkDBExist.Tables[0].Rows.Count == 0)
{
DialogResult result = MessageBox.Show("Database not found.\nDo you want to Restore Database?", "Restore Database", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
if (result == DialogResult.Yes)
{
try
{
Server mServer = new Server(@".\sqlexpress");
//mServer.KillAllProcesses("Transactions");
//mServer.DetachDatabase("Transactions", true);
//Application.StartupPath.Replace only needed at project devlopment
File.Move(Application.StartupPath.Replace("bin\\Debug", "") + @"TranDB\Transactions.mdf", @"C:\Program Files\Microsoft SQL Server\MSSQL.1\MSSQL\data\Transactions.mdf");
File.Move(Application.StartupPath.Replace("bin\\Debug", "") + @"TranDB\Transactions_log.ldf", @"C:\Program Files\Microsoft SQL Server\MSSQL.1\MSSQL\data\Transactions_log.ldf");
//File.Move(Application.StartupPath + @"TranDB\Transactions.mdf", @"C:\Program Files\Microsoft SQL Server\MSSQL.1\MSSQL\data\Transactions.mdf");
//File.Move(Application.StartupPath + @"TranDB\Transactions_log.ldf", @"C:\Program Files\Microsoft SQL Server\MSSQL.1\MSSQL\data\Transactions_log.ldf");
StringCollection files = new StringCollection();
files.Add(@"C:\Program Files\Microsoft SQL Server\MSSQL.1\MSSQL\data\Transactions.mdf");
files.Add(@"C:\Program Files\Microsoft SQL Server\MSSQL.1\MSSQL\data\Transactions_log.ldf");
mServer.AttachDatabase("Transactions", files, AttachOptions.None);
}
catch (Exception ex)
{
MessageBox.Show(ex.ToString());
}
}
}
return true;
}
6.The above code have my bll class which i use for connection above code to give some idea ;)
7.getSqlExpressPath() //to get sqlexpress path
{
string path = "";
using (RegistryKey sqlServerKey = Registry.LocalMachine.OpenSubKey(@"SOFTWARE\Microsoft\Microsoft SQL Server"))
{
foreach (string subKeyName in sqlServerKey.GetSubKeyNames())
{
if (subKeyName.StartsWith("MSSQL."))
{
using (RegistryKey instanceKey = sqlServerKey.OpenSubKey(subKeyName))
{
string instanceName = instanceKey.GetValue("").ToString();
if (instanceName == "SQLEXPRESS")//say
{
path = instanceKey.OpenSubKey(@"Setup").GetValue("SQLBinRoot").ToString();
path = Path.Combine(path, "sqlserver.exe");
}
}
}
}
}
return path;
}
http://www.prpraveen.blogspot.com
Posted by
Praveen P.R
Thursday, October 8, 2009
Backup DataBase as .bak sql express 2005 C# .Net By Praveen P.R
using Microsoft.SqlServer.Management;
using Microsoft.SqlServer.Management.Smo;
using Microsoft.SqlServer.Management.Common;
using System.Windows.Forms;
public void BackupDatabase(String databaseName, String userName, String password, String serverName, String destinationPath)
{
try
{
Backup sqlBackup = new Backup();
sqlBackup.Action = BackupActionType.Database;
sqlBackup.BackupSetDescription = "ArchiveDataBase:" + DateTime.Now.ToShortDateString();
sqlBackup.BackupSetName = "Archive";
sqlBackup.Database = databaseName;
BackupDeviceItem deviceItem = new BackupDeviceItem(destinationPath, DeviceType.File);
//Backup bu = new Backup();
//bu.Database = databaseName;
//bu.Devices.Add(deviceItem);
//bu.Initialize = true;
//bu.PercentCompleteNotification = 10;
//// add percent complete and complete event handlers
//bu.PercentComplete += new PercentCompleteEventHandler(Backup_PercentComplete);
//bu.Complete += new ServerMessageEventHandler(Backup_Complete);
//ServerConnection connection = new ServerConnection(serverName,userName,password);
ServerConnection connection = new ServerConnection(serverName);
Server sqlServer = new Server(connection);
Database db = sqlServer.Databases[databaseName];
sqlBackup.Initialize = true;
sqlBackup.Checksum = true;
sqlBackup.ContinueAfterError = true;
sqlBackup.Devices.Add(deviceItem);
sqlBackup.Incremental = false;
sqlBackup.ExpirationDate = DateTime.Now.AddDays(3);
sqlBackup.LogTruncation = BackupTruncateLogType.Truncate;
sqlBackup.FormatMedia = false;
sqlBackup.SqlBackup(sqlServer);
MessageBox.Show("Database Backup success....\nBackup file in " + destinationPath + ".", "Backup success", MessageBoxButtons.OK, MessageBoxIcon.None);
}
catch(Exception ex)
{
MessageBox.Show("Database Backup failed....", "Backup failed\n"+ex.InnerException.ToString () +"", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
http://www.prpraveen.blogspot.com
using Microsoft.SqlServer.Management.Smo;
using Microsoft.SqlServer.Management.Common;
using System.Windows.Forms;
public void BackupDatabase(String databaseName, String userName, String password, String serverName, String destinationPath)
{
try
{
Backup sqlBackup = new Backup();
sqlBackup.Action = BackupActionType.Database;
sqlBackup.BackupSetDescription = "ArchiveDataBase:" + DateTime.Now.ToShortDateString();
sqlBackup.BackupSetName = "Archive";
sqlBackup.Database = databaseName;
BackupDeviceItem deviceItem = new BackupDeviceItem(destinationPath, DeviceType.File);
//Backup bu = new Backup();
//bu.Database = databaseName;
//bu.Devices.Add(deviceItem);
//bu.Initialize = true;
//bu.PercentCompleteNotification = 10;
//// add percent complete and complete event handlers
//bu.PercentComplete += new PercentCompleteEventHandler(Backup_PercentComplete);
//bu.Complete += new ServerMessageEventHandler(Backup_Complete);
//ServerConnection connection = new ServerConnection(serverName,userName,password);
ServerConnection connection = new ServerConnection(serverName);
Server sqlServer = new Server(connection);
Database db = sqlServer.Databases[databaseName];
sqlBackup.Initialize = true;
sqlBackup.Checksum = true;
sqlBackup.ContinueAfterError = true;
sqlBackup.Devices.Add(deviceItem);
sqlBackup.Incremental = false;
sqlBackup.ExpirationDate = DateTime.Now.AddDays(3);
sqlBackup.LogTruncation = BackupTruncateLogType.Truncate;
sqlBackup.FormatMedia = false;
sqlBackup.SqlBackup(sqlServer);
MessageBox.Show("Database Backup success....\nBackup file in " + destinationPath + ".", "Backup success", MessageBoxButtons.OK, MessageBoxIcon.None);
}
catch(Exception ex)
{
MessageBox.Show("Database Backup failed....", "Backup failed\n"+ex.InnerException.ToString () +"", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
http://www.prpraveen.blogspot.com
Posted by
Praveen P.R
Wednesday, October 7, 2009
Restore .bak file sql express 2005 C# .Net By Praveen P.R
using Microsoft.SqlServer.Management.Smo;
using Microsoft.SqlServer.Management.Common;
using System.Windows.Forms;
public void RestoreDatabase(string databaseName,string backupFileName,String serverName)
{
try
{
ServerConnection connection = new ServerConnection(serverName);//".\sqlexpress"
Server server = new Server(connection);
Restore restore = new Restore();
restore.Database = databaseName;//
//backupFileName e.g database.bak
restore.Devices.AddDevice(backupFileName, DeviceType.File);
restore.ReplaceDatabase = true;
restore.ReplaceDatabase = true;
restore.PercentCompleteNotification = 10;
server.KillAllProcesses(databaseName);
restore.Wait();
restore.SqlRestore(server);
MessageBox.Show("Database Restore success....", "Restore success", MessageBoxButtons.OK, MessageBoxIcon.None);
}
catch (Exception ex)
{
System.Windows.Forms.MessageBox.Show(ex.InnerException.ToString());
}
}
http://www.prpraveen.blogspot.com
using Microsoft.SqlServer.Management.Common;
using System.Windows.Forms;
public void RestoreDatabase(string databaseName,string backupFileName,String serverName)
{
try
{
ServerConnection connection = new ServerConnection(serverName);//".\sqlexpress"
Server server = new Server(connection);
Restore restore = new Restore();
restore.Database = databaseName;//
//backupFileName e.g database.bak
restore.Devices.AddDevice(backupFileName, DeviceType.File);
restore.ReplaceDatabase = true;
restore.ReplaceDatabase = true;
restore.PercentCompleteNotification = 10;
server.KillAllProcesses(databaseName);
restore.Wait();
restore.SqlRestore(server);
MessageBox.Show("Database Restore success....", "Restore success", MessageBoxButtons.OK, MessageBoxIcon.None);
}
catch (Exception ex)
{
System.Windows.Forms.MessageBox.Show(ex.InnerException.ToString());
}
}
http://www.prpraveen.blogspot.com
Posted by
Praveen P.R
Subscribe to:
Posts (Atom)