Trouble logging into sql server

Please support our C# advertiser: Intel Parallel Studio Home
Reply

Join Date: Feb 2009
Posts: 66
Reputation: MJV is an unknown quantity at this point 
Solved Threads: 0
MJV MJV is offline Offline
Junior Poster in Training

Trouble logging into sql server

 
0
  #1
Mar 5th, 2009
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();
}
}

}
Reply With Quote Quick reply to this message  
Join Date: Aug 2007
Posts: 111
Reputation: ChaseVoid is an unknown quantity at this point 
Solved Threads: 12
ChaseVoid's Avatar
ChaseVoid ChaseVoid is offline Offline
Junior Poster

Re: Trouble logging into sql server

 
0
  #2
Mar 5th, 2009
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.
Reply With Quote Quick reply to this message  
Join Date: Aug 2008
Posts: 1,735
Reputation: LizR has a spectacular aura about LizR has a spectacular aura about 
Solved Threads: 186
LizR LizR is offline Offline
Posting Virtuoso

Re: Trouble logging into sql server

 
0
  #3
Mar 5th, 2009
Do be aware that the dev SQL server has limited connections too.
Did I just hear "You gotta help us, Doc. We've tried nothin' and we're all out of ideas" ? Is this you? Dont let this be you! I will put in as much effort as you seem to.
Reply With Quote Quick reply to this message  
Join Date: Feb 2009
Posts: 66
Reputation: MJV is an unknown quantity at this point 
Solved Threads: 0
MJV MJV is offline Offline
Junior Poster in Training

Re: Trouble logging into sql server

 
0
  #4
Mar 5th, 2009
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
Reply With Quote Quick reply to this message  
Join Date: Feb 2009
Posts: 66
Reputation: MJV is an unknown quantity at this point 
Solved Threads: 0
MJV MJV is offline Offline
Junior Poster in Training

Re: Trouble logging into sql server

 
0
  #5
Mar 5th, 2009
What do you mean by dev SQL?
Reply With Quote Quick reply to this message  
Join Date: Aug 2008
Posts: 1,735
Reputation: LizR has a spectacular aura about LizR has a spectacular aura about 
Solved Threads: 186
LizR LizR is offline Offline
Posting Virtuoso

Re: Trouble logging into sql server

 
0
  #6
Mar 5th, 2009
The free one that comes with visual studio ..
Did I just hear "You gotta help us, Doc. We've tried nothin' and we're all out of ideas" ? Is this you? Dont let this be you! I will put in as much effort as you seem to.
Reply With Quote Quick reply to this message  
Join Date: Aug 2007
Posts: 111
Reputation: ChaseVoid is an unknown quantity at this point 
Solved Threads: 12
ChaseVoid's Avatar
ChaseVoid ChaseVoid is offline Offline
Junior Poster

Re: Trouble logging into sql server

 
0
  #7
Mar 5th, 2009
To enable pooling:
  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:
  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.
Reply With Quote Quick reply to this message  
Join Date: Nov 2006
Posts: 436
Reputation: JerryShaw is on a distinguished road 
Solved Threads: 72
JerryShaw JerryShaw is offline Offline
Posting Pro in Training

Re: Trouble logging into sql server

 
0
  #8
Mar 5th, 2009
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.
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the C# Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC