CE如何才能连接SQLserver2005啊
如题
我是用VB.NET的
在项目中引用了system.data.sqlclient
在软件中定义了sqlconnection
conn.ConnectionString = "Persist Security Info=False; Integrated Security=SSPI; Data Source=192.168.2.10; database=AIS20091020085835; User ID=sa; Password=123"
conn.open()提示错误。。用户''登陆失败,该用户与可信SQL SERVER连接无关联
请各位大哥麻烦看看解决下啊~~!小弟很急~!!谢谢
[解决办法]
用连接字串就可以:
c# code:
private void button2_Click(object sender, EventArgs e) { string connString = "Data Source=192.168.1.3;user id=sa;pwd=sa;Initial Catalog=ghxtest"; SqlConnection conn = new SqlConnection(connString); try { conn.Open(); //MessageBox.Show("连接成功!", "信息提示", MessageBoxButtons.OK, MessageBoxIcon.Asterisk, MessageBoxDefaultButton.Button1); SqlCommand mycmd = conn.CreateCommand(); //insert or update //mycmd.CommandText = "insert into stu values('6s','136')"; //mycmd.ExecuteNonQuery(); mycmd.CommandText = "select stuname from stu ";//where stuid='111'"; SqlDataReader drdr = mycmd.ExecuteReader(); while (drdr.Read()) { MessageBox.Show(drdr.GetString(0), "信息提示", MessageBoxButtons.OK, MessageBoxIcon.Asterisk, MessageBoxDefaultButton.Button1); } } catch (SqlException se) { MessageBox.Show("连接失败!", "错误提示", MessageBoxButtons.OK, MessageBoxIcon.Hand, MessageBoxDefaultButton.Button1); //log.Error(se.ToString()); } catch (Exception ex) { MessageBox.Show("连接失败!" + ex.Message, "错误提示", MessageBoxButtons.OK, MessageBoxIcon.Hand, MessageBoxDefaultButton.Button1); //log.Error(ex.ToString()); } finally { if (conn.State == ConnectionState.Open) { conn.Close(); } } }