October 29th, 2011, 12:46 PM
Hi all and thanks in advanced for the help.
I am VERY New to C#, and I have been playing around by watching videos in youtube etc.
I come from the Delphi world. This is the problem I am getting
In my delphy ADOconnection String (Which works very well) I have
Data Source: 0166-PC\PDSTAFFING
Initial Catalog: PDSTAFFING
User ID: calosa_canis
I am using Windows authentication to login into the Database
In my C#2010 I have the following but I can't connect and gives me a Login Failure error.
Hope you can help me out
Once again thanks for all the help.
public partial class Form1 : Form
SqlConnection MainConnection = new SqlConnection("Data Source=0166-PC\\PDSTAFFING;User Id=carlosa_canis;Initial Catalog=PDSTAFFING;");
private void button1_Click(object sender, EventArgs e)
catch (Exception error)
October 30th, 2011, 09:59 AM
Re: Connection String
Btw, you might want to let the database provider do it's job and manage the connection caching.
In other words, it's tempting to want to open a connection and hold it open for a while because it seem inefficient to open/close connections all the time. The reality is that the database provider (SqlConnection) is smart, so when you call Close, it really just returns that connection to an internal connection pool instead of really closing the db connection.
Given that, you should simply open a connection, do the work and then close the connection. To help with this, wrap the connection in a 'using' block (as it will call Close/Dispose automatically for you).
using( var cn = new SqlConnection("Server=0166-PC\PDSTAFFING;Database=PDSTAFFING;Integrated Security=TRUE") )
using( var cmd = new SqlCommand( ..., cn ) )
// use the sql command
} // SqlCommand object gets auto-cleaned up here
} // SqlConnection object gets auto-cleaned up here
catch( Exception ex )
Last edited by Arjay; October 30th, 2011 at 10:10 AM.
Click Here to Expand Forum to Full Width
This is a Codeguru.com survey!