Can any one help me to identify the error in this program using ADO.NET...
Code:
using System;
using System.Collections.Generic;
using System.Text;
using System.Data;
using System.Data.SqlClient;
using System.Transactions; // the code is showing an error in this line
class Program
{
static void Main(string[] args)
{
try
{
string connectString = "Initial Catalog=AdventureWorks;
Data Source=SQLSERVER01;
User id =user;password=password";
SqlConnection con = new SqlConnection();
con.ConnectionString = connectString;
con.Open();
SqlTransaction tr = null;
tr = con.BeginTransaction();
SqlCommand cmd = new SqlCommand("INSERT INTO sunny1(name, id, city, phone, pincode) VALUES ('sandy', 01441, 'abc', 'phone', 122001)", con, tr);
cmd.ExecuteNonQuery();
tr.Commit();
Console.WriteLine("transaction completed ");
}
catch (SqlException e)
{
tr.Rollback();
Console.WriteLine("teansaction not completed " + e.Message);
}
catch (System.Exception ex)
{
Console.WriteLine("system error " + ex.Message);
}
finally
{
cn.Close();
}
Console.ReadLine();
}
}
The code also shows an error message related to some missing assembly.