how can i create a setup of C# application with its SQL Server Database within its file means only one exe file which contain database with in it...means everything (database and source code) is in one file...
if you know how to do it then please help me......
i need to know this thing for my college project....which is in C# with SQL Server 2005 and 2008 (Support both versions of SQL servers)....
Loading

Sudhakar ChaudharyPosted Oct 29, 2012, 9:46 AM
here a sample...
public void RestoreDatabase(String databaseName, String filePath, String serverName, String userName, String password, String dataFilePath, String logFilePath)
{
Restore sqlRestore = new Restore();
BackupDeviceItem deviceItem = new BackupDeviceItem(filePath, DeviceType.File);
sqlRestore.Devices.Add(deviceItem);
sqlRestore.Database = databaseName;
ServerConnection connection;
// for Windows Authentication
if (userName == "")
{
SqlConnection sqlCon = new SqlConnection(@"Data Source=" + serverName + @"; Integrated Security=True;");
connection = new ServerConnection(sqlCon);
}
// for Server Authentication
else
connection = new ServerConnection(serverName, userName, password);
Server sqlServer = new Server(connection);
Database db = sqlServer.Databases[databaseName];
sqlRestore.Action = RestoreActionType.Database;
String dataFileLocation = dataFilePath + databaseName + ".mdf";
String logFileLocation = logFilePath + databaseName + "_Log.ldf";
db = sqlServer.Databases[databaseName];
RelocateFile rf = new RelocateFile(databaseName, dataFileLocation);
sqlRestore.RelocateFiles.Add(new RelocateFile(databaseName, dataFileLocation));
sqlRestore.RelocateFiles.Add(new RelocateFile(databaseName + "_log", logFileLocation));
sqlRestore.ReplaceDatabase = true;
sqlRestore.Complete += new ServerMessageEventHandler(sqlRestore_Complete);
sqlRestore.PercentCompleteNotification = 10;
sqlRestore.PercentComplete += new PercentCompleteEventHandler(sqlRestore_PercentComplete);
try
{
sqlRestore.SqlRestore(sqlServer);
}
catch (Exception ex)
{
MessageBox.Show(ex.InnerException.ToString());
}
db = sqlServer.Databases[databaseName];
db.SetOnline();
sqlServer.Refresh();
}
Shivanand ArurPosted Oct 29, 2012, 9:20 AM
Thank you!!!
Kaushal SutharPosted Oct 29, 2012, 8:33 AM
Shivanand ArurPosted Oct 21, 2012, 3:50 AM
Plus, the changes that you make in your Database using your Sequel Management Studio, the changes are again reflected back in your project.... So if you create a new Procedure or a Function using your Sql Management Studio, it is shown in your Project's Server Explorer.
I hope this what you wanted to know... Thanks!!!