Execute 2 large SQL scripts from C# Web Form
$13-18 USD
Paid on delivery
Hello,
I am witting an ecommerce application. during the setup process I need to execute two SQL scripts to a SQL 2005 or 2008 server.
The script work fine I have tested them many times, however executing them via C# gives me a few errors.
Your task is to modify the code snippet **below** so the SQL script will execute without problems.
1. You **cannot** modify the sql scripts, leave them as they are.
2. SQL scripts are **attached** in the zip file
3. **Below** is the code I currently use, please use this as a base.
4. Your code must handle any find/replace and/or formatting requirements.
5. Test this thoroughly on your side, do not send me buggy code
6. **If you** can do anything special or **have any other recommendations** **mention that in your bid**. I always read these.
I posted this on experts exchange and got some tips, see:
[url removed, login to view]
## Deliverables
public static bool ExecuteSQLScript(string Host, string Database, string User, string Password, string SqlScript)
{
// Test DB
string host = [url removed, login to view](Host);
string db = [url removed, login to view](Database);
string user = [url removed, login to view](User);
string pass = [url removed, login to view](Password);
//Create and Open Connection
SqlConnection conn = new SqlConnection();
if (![url removed, login to view](pass))
conn = new SqlConnection([url removed, login to view]("Data Source={0};UID={1}; PWD={2}; Initial Catalog={3};", host, user, pass, db));
else
conn = new SqlConnection([url removed, login to view]("Server={0};Database={1};Trusted_Connection=yes;", host, db));
bool worked = false;
string count = [url removed, login to view];
SqlCommand cmd = new SqlCommand(SqlScript, conn);
SqlScript = [url removed, login to view]("GO", ""); // does this help??
try
{
[url removed, login to view]();
[url removed, login to view]();
worked = true;
}
catch
{
worked = false;
}
finally
{
[url removed, login to view]();
}
return worked;
}
Project ID: #3818699