R
Rick
Hi guys, me again XD
I want to identify what i'm doing wrong, let me explain:
I have a SQL Express instance on my PC (ip 192.168.1.40)
I've configured SQL Express to allow remote TCP/IP connections and changed
the port number to 1433 as explain this page
http://netcf2.blogspot.com/2005/12/accessing-sql-server-express-from.html
I've restarted SQL Express
In VS2005 i've created a new data source using assistant, the resulting
string connection is
Data Source=192.168.1.40,1433;Initial Catalog=mobile6;Persist Security
Info=True;User ID=mobile6;Password=mobile6
I dragged the table in dataset to a mobile form and it's all ok, when i run
my app on the device it works fine, shows me data from datasource
But if i try to make a "manual" connection to database i just got an
SqlException and no more info, i've debbuged it, but i dont have more
information, why the dataset connects and shows info, and when i try to use
the same string connection i can't open the connection?
my code is:
SqlConnection Cnn = new SqlConnection("Data Source=192.168.1.40,1433;Initial
Catalog=mobile6;Persist Security Info=True;User
ID=mobile6;Password=mobile6");
SqlCommand Cmd = new SqlCommand("", Cnn);
String lsSql;
try
{
//when debug the app, Cnn can't be open, but doesn't says why
Cnn.Open();
//just an insert to a table without keys, just testing but i can't pass from
the line above, it trys to open, then send Exception
lsSql = "insert into tabla_test (nombre,edad,ciudad,telefono) values ('" +
textBox1.Text + "'," + textBox2.Text + ",'" + textBox3.Text + "','" +
textBox4.Text + "')";
Cmd.CommandText = lsSql;
Cmd.ExecuteNonQuery();
}
catch (Exception ex)
{
//this just shows SqlException and no more
MessageBox.Show(ex.Message + "\n" + ex.GetType().ToString(), "Error",
MessageBoxButtons.OK,
MessageBoxIcon.Exclamation,MessageBoxDefaultButton.Button1);
}
finally { if (Cnn.State == ConnectionState.Open) { Cnn.Close(); } }
Regards
Rick
I want to identify what i'm doing wrong, let me explain:
I have a SQL Express instance on my PC (ip 192.168.1.40)
I've configured SQL Express to allow remote TCP/IP connections and changed
the port number to 1433 as explain this page
http://netcf2.blogspot.com/2005/12/accessing-sql-server-express-from.html
I've restarted SQL Express
In VS2005 i've created a new data source using assistant, the resulting
string connection is
Data Source=192.168.1.40,1433;Initial Catalog=mobile6;Persist Security
Info=True;User ID=mobile6;Password=mobile6
I dragged the table in dataset to a mobile form and it's all ok, when i run
my app on the device it works fine, shows me data from datasource
But if i try to make a "manual" connection to database i just got an
SqlException and no more info, i've debbuged it, but i dont have more
information, why the dataset connects and shows info, and when i try to use
the same string connection i can't open the connection?
my code is:
SqlConnection Cnn = new SqlConnection("Data Source=192.168.1.40,1433;Initial
Catalog=mobile6;Persist Security Info=True;User
ID=mobile6;Password=mobile6");
SqlCommand Cmd = new SqlCommand("", Cnn);
String lsSql;
try
{
//when debug the app, Cnn can't be open, but doesn't says why
Cnn.Open();
//just an insert to a table without keys, just testing but i can't pass from
the line above, it trys to open, then send Exception
lsSql = "insert into tabla_test (nombre,edad,ciudad,telefono) values ('" +
textBox1.Text + "'," + textBox2.Text + ",'" + textBox3.Text + "','" +
textBox4.Text + "')";
Cmd.CommandText = lsSql;
Cmd.ExecuteNonQuery();
}
catch (Exception ex)
{
//this just shows SqlException and no more
MessageBox.Show(ex.Message + "\n" + ex.GetType().ToString(), "Error",
MessageBoxButtons.OK,
MessageBoxIcon.Exclamation,MessageBoxDefaultButton.Button1);
}
finally { if (Cnn.State == ConnectionState.Open) { Cnn.Close(); } }
Regards
Rick