I have a solutin with forms that use table adapters to input data into sql tables and that all works fine. My trouble comes when I have another form that uses a sql stored procedure. When I try to connect to the server I get an error that the login failed. Im using the same type of connection as I did for my dataset to login and that was integrated security. Is this problem because I'm already in the data base with the solution and then I try to open another connection with the following code for the execution of a stored procedure? Any help would be greatly apprecieated. I have also used the line Integrated Security = True but this did not work either.
private void approveestBN_Click(object sender, EventArgs e)
{
//string ConnectionString = "Data Source={0};Initial Catalog={1};Integrated Security=True";
string ConnectionString = "Data Source={0};Initial Catalog={1};Trusted_Connection=True";
int estno;
if (int.TryParse(startestnoCB.Text, out estno))
{
SqlConnection conn = new SqlConnection(string.Format(ConnectionString, "server1", "Estimate"));
SqlCommand cmd = new SqlCommand("EstimateApproval", conn);
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.AddWithValue("@Estno", estno);
try
{
conn.Open();
#if WantSomethingBack
DataTable result = new DataTable();
SqlDataAdapter adapter = new SqlDataAdapter(cmd);
adapter.Fill(result);
foreach(DataRow row in result.Rows)
{
}
result.Dispose()
#else
cmd.ExecuteNonQuery(); // If you do not need a return;
#endif
}
catch (SqlException err)
{
MessageBox.Show(err.Message);
}
finally
{
if (conn.State == ConnectionState.Open)
conn.Close();
conn.Dispose();
}
}
}