943,864 Members | Top Members by Rank

Ad:
  • C# Discussion Thread
  • Unsolved
  • Views: 871
  • C# RSS
Mar 5th, 2009
0

Trouble logging into sql server

Expand Post »
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();
}
}

}
Similar Threads
MJV
Reputation Points: 10
Solved Threads: 0
Junior Poster in Training
MJV is offline Offline
66 posts
since Feb 2009
Mar 5th, 2009
0

Re: Trouble logging into sql server

Well if you are using multiple connections, then you can try enabling pooling. MARS is also an option that uses a single connection to execute multiple queries, however is restricted to only DataReaders.
Reputation Points: 40
Solved Threads: 12
Junior Poster
ChaseVoid is offline Offline
116 posts
since Aug 2007
Mar 5th, 2009
0

Re: Trouble logging into sql server

Do be aware that the dev SQL server has limited connections too.
Reputation Points: 196
Solved Threads: 190
Posting Virtuoso
LizR is offline Offline
1,735 posts
since Aug 2008
Mar 5th, 2009
0

Re: Trouble logging into sql server

Not a well seasoned programmer. Are you saying I have to enable pooling or MARS to make this work . If so can you explain.
Thanks
MJV
Reputation Points: 10
Solved Threads: 0
Junior Poster in Training
MJV is offline Offline
66 posts
since Feb 2009
Mar 5th, 2009
0

Re: Trouble logging into sql server

What do you mean by dev SQL?
MJV
Reputation Points: 10
Solved Threads: 0
Junior Poster in Training
MJV is offline Offline
66 posts
since Feb 2009
Mar 5th, 2009
0

Re: Trouble logging into sql server

The free one that comes with visual studio ..
Reputation Points: 196
Solved Threads: 190
Posting Virtuoso
LizR is offline Offline
1,735 posts
since Aug 2008
Mar 5th, 2009
0

Re: Trouble logging into sql server

To enable pooling:
C# Syntax (Toggle Plain Text)
  1. String connectionString = "Data Source=./SQLExpress; Initial Catalog=StudentDetails; Integrated Scurity=SSPI; Connection Timeout=20; Pooling = true";
You can also specfy the Min pool size and Max pool size

To enable MARS:
C# Syntax (Toggle Plain Text)
  1. String connectionString = "Data Source=./SQLExpress; Initial Catalog=StudentDetails; Integrated Scurity=SSPI; MultipleActiveResultSets = True";

I don't know why you are getting an error when your accessing the database using two connections. It shouldn't create a problem for the server if the same user connects to it twice using different connections.
Reputation Points: 40
Solved Threads: 12
Junior Poster
ChaseVoid is offline Offline
116 posts
since Aug 2007
Mar 5th, 2009
0

Re: Trouble logging into sql server

MJV,
Run it in debug mode, and see what the InnerException.Messge is telling you. (post it here if you do not understand it)

The syntax of the code looks right. You can have many connections to SqlExpress if that is what you are using. I have applications with many threads hitting an SqlExpress with no issues. MS recommends limiting to 5, but that is only a recommendation. I have never seen it reject a login due to the number of connections( at least on SqlExpress).

Viewing the InnerException should tell you exactly what is going on.
Reputation Points: 69
Solved Threads: 75
Posting Pro in Training
JerryShaw is offline Offline
465 posts
since Nov 2006

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in C# Forum Timeline: Can someone explain the concept of bitmap animations to me
Next Thread in C# Forum Timeline: Validation





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC