Re: Huge problem with sql!
Since you are connecting to SQL Server, why not use the SqlConnection and SqlCommand classes in the SqlClient namespace?
Code:
using( SqlConnection cn = new SqlConnection( "connection str ") )
{
// Query the db
using( SqlCommand cmd = cn.CreateCommand() )
{
cmd.CommandText = "SELECT user FROM users";
cn.Open();
// run the query
SqlDataReader reader = cmd.ExecuteReader();
while ( reader.Read( ) )
{
activeusertextBox.Text1 = Convert.ToString( reader["col1"] );
activeusertextBox.Text2 = Convert.ToString( reader["col2"] );
}
}
}
If have to use Odbc, then you'll need to close your OdbcCommand objects (or use them in a using block).
Re: Huge problem with sql!
i think i already done that,
Code:
using (OdbcConnection cn = new OdbcConnection())
{
cn.Close();
}
but i think cn.Close(); doesn't need to be there.
anyway
i think that my problems start when i connect first time to database, then even though i close my connections the database seems to be "locked" and this
Code:
this.myTableAdapter.Fill(this.myDataSet.charge);
doesn't work
but if i make a new form with only this
Code:
this.myTableAdapter.Fill(this.myDataSet.charge);
it works perfect!
Re: Huge problem with sql!
ok it seems to work with sqlconnection as you posted before, but is there a way not to store the password inside my code ? is there a way to give as connection string my dsn ?
Code:
using( SqlConnection cn = new SqlConnection( "connection str ") )
{
// Query the db
using( SqlCommand cmd = cn.CreateCommand() )
{
cmd.CommandText = "SELECT user FROM users";
cn.Open();
// run the query
SqlDataReader reader = cmd.ExecuteReader();
while ( reader.Read( ) )
{
activeusertextBox.Text1 = Convert.ToString( reader["col1"] );
activeusertextBox.Text2 = Convert.ToString( reader["col2"] );
}
}
}
this is only to get values from database ?? if i want to use a insert statement ?
Re: Huge problem with sql!
Read my previous response carefully - I said to use a using block on the OdbcCommand objects and the OdbcConnection objects.
The problem is that you aren't freeing the resources, so eventually the db refuses you.
As far as putting the password in plain text in the config file. You can use integrated windows security or encrypt the password in the config file. There are many approaches to this. I searched google for "connection string password encryption" and came up with this one: http://ondotnet.com/pub/a/dotnet/200...onnstring.html
To insert a record, form the INSERT statement and call cmd.ExecuteNonQuery( ). For more info and examples, search google for "SqlCommand insert example".
Re: Huge problem with sql!
thanks, i managed to do it i'll search about password encryption