I use C# and need to install SQL Server 2005 Express edition in silent mode in my project and use code below, but for the first time, SQL Server do not install correctly . Sql database engine do not install.. When I uninstall SQL Server 2005 Express edition from windows and install it from my project, it correctly installs.
What's wrong in my project ?
ProcessStartInfo psSqlServer = new ProcessStartInfo(Application.StartupPath + "\\SQLEXPR\\setup.exe ", "/qn ADDLOCAL=ALL INSTANCENAME=MSSQLSERVER SECURITYMODE=SQL SAPWD=123 SQLAUTOSTART=1 DISABLENETWORKPROTOCOLS=0");
Process pSqlServer = Process.Start(psSqlServer);
pSqlServer.WaitForExit();
Process pro = new Process();
pro.StartInfo.FileName = Application.StartupPath + "\SQLEXPR\setup.exe";
pro.StartInfo.Arguments = "/qs ADDLOCAL=ALL INSTANCENAME=MSSQLSERVER SECURITYMODE=SQL SAPWD=123 SQLAUTOSTART=1 DISABLENETWORKPROTOCOLS=0";
pro.StartInfo.CreateNoWindow = true;
pro.Start();
pro.WaitForExit();
Related
I am running an automated test using C# and Coded UI Tests on Window Server 2016. I am using the process.start method to launch an installer but when the test launches the installer, the window is blank and cannot be used either by the test or manually.
This does not happen when I launch the installer manually (works fine) or on any other OS (only happens on Server 2016).
Everything is running as admin. I have updated windows itself and video drivers.
Here is the code used to launch the installer:
public void LaunchUnifiedDashboardInstaller(bool upgrade = false)
{
string pathtoInstaller = "";
// Get path to installer
if (upgrade == false)
{
pathtoInstaller = TestRunSettings.TestSetting.GetPathToInstallers();
}
else if (upgrade == true)
{
pathtoInstaller = TestRunSettings.TestSetting.GetPathToUpgradeInstaller();
}
//string pathtoInstaller = #"E:\";
Console.WriteLine("LaunchUnifiedDashboardInstaller() - Path to installer is: " + pathtoInstaller);
TestReport.WriteText("Launching Unified Dashboard setup .... ");
//Server Installer
System.Diagnostics.ProcessStartInfo proc = new System.Diagnostics.ProcessStartInfo(pathtoInstaller + #"\setup.exe");
//proc.UseShellExecute = true;
//proc.Verb = "runas";
System.Diagnostics.Process.Start(proc);
TestReport.WriteText("Launching Unified Dashboard setup .... ");
}
screenshot of blank windows
This one has me totally stumped. Has anyone seen this before?
Thanks
Richard
Fixed it. Sort of.
This was happening using Server 2016 with all the available updates applied.
So I went back to the base original release of Server 2016 (from 2016) and turned off Windows update. Lo and behold, it now works fine. Something in a newer Windows version must have disagreed with Coded UI.
I have an windows application developed in C#, I need to install it on a PC which will just have the Operating System and .Net Framework installed. Now I have to give an option to install SQL Server 2008 R2 Express edition on that PC, using this windows application. I have coded for installing/uninstalling a windows service, but struck with sql server installation. could someone help me out in doing this.
Follow the guidelines in How to Embed SQL Server Express in an Application. It covers everything you need, including pickiing up the right distribution, choosing an appropriate installation method (wpi vs. setup.exe) and how to configure the installation. the wiki even has a C# code on how to detect a previous Express instalation, how to invoke the WPI (Web Platform Installer) for SQL Express from C#:
System.Diagnostics.Process.Start(
#"C:\Program Files\Microsoft\Web Platform Installer\webplatforminstaller.exe",
" /id SQLExpress");
or using the "wpi://" URL handler:
System.Diagnostics.Process.Start("wpi://SQLExpress/");
or using the Web App Galery:
System.Diagnostics.Process.Start(
"http://www.microsoft.com/web/gallery/install.aspx?appsxml=&appid=SQLExpress");
and, finally, using the SQL Express setup (recommended for advanced configuration):
System.Diagnostics.Process processObj =
System.Diagnostics.Process.Start(#"c:\temp\sqlsetup\setup.exe",
#"/q /Action=Install /Hideconsole /IAcceptSQLServerLicenseTerms=True
/Features=SQL,Tools /InstanceName=SQLExpress
/SQLSYSADMINACCOUNTS=""Builtin\Administrators""
/SQLSVCACCOUNT=""DomainName\UserName"" /SQLSVCPASSWORD=""StrongPassword""");
and it has the full list of setup parameters.
You can use msiexec.exe. You can simply install an MSI by passing the MSI path. Using command you can set whether to show UI during the installation or make it a silent installation,
string installCommandString = "/i {0} /qn";
/qn: Set user interface level: None
/qb: Set user interface level: Basic UI
/qr: Set user interface level: Reduced UI
/qf: Set user interface level: Full UI (default)
C# code
string installCommandString = "/i {0} /qn";
Process process = new Process();
ProcessStartInfo startInfo = new ProcessStartInfo();
process.StartInfo = startInfo;
startInfo.UseShellExecute = false;
startInfo.RedirectStandardError = true;
startInfo.FileName = "msiexec.exe";
startInfo.Arguments = string.Format(installCommandString, "SQL Server MSI Path");
process.Start();
If you are using the standard MSI installer, built into Visual Studio then there is an option to set pre-requisites.
Right click the MSI
Select properties
Select prerequisites
Near the bottom there is an option for SQL Server Express and you can specify where to get the components from - vendor, or from a location on your servers.
I am getting error when I am trying to open connection. My DB.sdf file is in my application folder
here i stored db.sdf
{
string ConnectionString= new System.IO.FileInfo(System.Reflection.Assembly.GetExecutingAssembly().Location).DirectoryName + #"\APP_DATA\DB.sdf";
public int ExecuteNonQuery(string query){
int res = -1;
try
{
using (SqlCeConnection conn = new SqlCeConnection(ConnectionString))
{
SqlCeCommand command = new SqlCeCommand(query, conn);
command.CommandType = CommandType.Text;
conn.Open();
res = command.ExecuteNonQuery();
}
}
catch (Exception e)
{
new Logs().TraceProcessError(e.Message);
}
return res;
}
}
Error:
You are trying to access an older version of a SQL Server Compact
Edition database. If this is a SQL Server CE 1.0 or 2.0 database, run
upgrade.exe. If this is a SQL Server Compact Edition 3.0 or later
database, run Compact / Repair. [ Db version = 3505053,Requested
version = 3004180,File name = D:\DB.sdf ]"
and I am using SQL Server Compact 3.5., VS2010, SQLServer 2008R2.
please help.
thanks.
Can you please refer to the link below:
http://social.msdn.microsoft.com/Forums/sqlserver/en-US/058357a2-e8a2-447e-82dc-df4466542855/trying-to-open-a-sql-compact-db-in-vb2005-created-it-in-vb2008?forum=sqlce
Hope it helps..!!
Make sure that you (1) know which version of SQL Server CE you database is, and (2) that you reference the appropriate System.Data.SqlServerCe.DLL from you project that matches that version of SQL CE.
Download SQL Server compact toolbox from here
https://sqlcetoolbox.codeplex.com/
Run it against your data base file and note down the version number (eg. 3.5)
Go into visual studio click on System.Data.SqlServerCe under resources and then click under the properties. In properties note down the version number (eg. 3.0)
If the the library version number is older. Download the SQL Server Compact installer and run.
http://www.microsoft.com/en-IE/download/details.aspx?id=12264
Once installed. Delete the references to System.Data.SqlServerCe and System.Data.SqlClient from your project and add their equivalent 3.5 versions. Found on my system at.
C:\Program Files (x86)\Microsoft SQL Server Compact Edition\v3.5\Devices\System.Data.SqlServerCe.dll
and
C:\Program Files (x86)\Microsoft SQL Server Compact Edition\v3.5\Devices\Client\System.Data.SqlClient.dll
Clean and then rebuild. Like I mentioned in the comment, this undid itself at some point on VS 2008 so if you get the error again double check the path is going to the above.
We create an Sql DB Bakup through application using the code below:
ServerConnection srvConn = new ServerConnection(HostName);
srvConn.LoginSecure = true;
Server srvSql = new Server(srvConn);
string FileName = Environment.GetFolderPath(Environment.SpecialFolder.Desktop)
+"//Closing Back-Up");
bkpDatabase.Database = database;
BackupDeviceItem bkpDevice = new BackupDeviceItem(FileName, DeviceType.File);
bkpDatabase.Devices.Add(bkpDevice);
bkpDatabase.SqlBackup(srvSql);
It works fine for Drives excluding the Drive where OS is installed due to right problems. In the drive with OS it says:Cannot open backup device. I searched it on internet and SO, but it suggests to manually change Built-In account from "Network Service" to "Local System" using SQL Server Configuration Manager.
But we distribute our software online and via CD's for self installation, so it is impossible to instruct each and every client to do so as they may not be technically well-versed with it.
So the question is, can we change the built-in account via Script ? Or is there any other solution that we can perform via program or script ?
Thank you.
Edit:
We distribute SQL Server 2008 Express as a pre-requisite and downloaded from same folder as my application. The prerequisite doesn't ask for any account settings or instance-name etc settings, which we find in SQL Server manual installation procedure.
Not sure this will work or not but You can try to run the program as administrator through code. There is a good article how to run program with admin rights.
How to force my C# Winforms program run as administrator on any computer?
I have some trouble installing Management Studio 2008 Express through C#-Code.
The code looks like this:
using (Process MMSInstall = new Process())
{
var psi = new ProcessStartInfo(PathExe.FullName, "/qs /Features=SSMS /Action=Install");
MMSInstall.StartInfo = psi;
MMSInstall.Start();
MMSInstall.WaitForExit();
}
PathExe is a FileInfo-Instance.
But the installation always fails:
Exception type: Microsoft.SqlServer.Setup.Chainer.Workflow.NoopWorkflowException
Message:
No features were installed during the setup execution. The requested features may already be installed. Please review the summary.txt log for further details.
When installing via command prompt
C:\>SQLMANAGEMENTSTUDIO_X86_DEU.EXE /qs /Features=SSMS /Action=Install
everything works fine.
I looked through the logfiles (Detail.txt), and spottet a difference:
When running from the command prompt, 'Setting: MEDIALAYOUT' is set to 'Advanced' (pastebin.org/36222), when installing from my little C#-App it's set to 'Core' (pastebin.org/36221)
I tried to append /MEDIALAYOUT=Advanced to the ProcessStartInfo-Arguments in my code, but this options is ignored. I don't know what this parameter does, and I could not find any documentation about it.
Any ideas how to solve this or where to look for?
I am testing on Windows Vista Ultimate SP1
instead of calling the executable directly call %windir%\system32\cmd.exe
Cmd has a /C switch which allows you to pass in a command to run. So you'd pass in '/c "SQLMANAGEMENTSTUDIO_X86_DEU.EXE /qs /Features=SSMS /Action=Install"'
as a parameter.