最新下载
热门教程
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
asp.net 连接mssql 2005代码与实例
时间:2022-06-25 06:05:55 编辑:袖梨 来源:一聚教程网
asp教程.net 连接mssql 2005代码与实例
SqlConnection sql = new SqlConnection(@"server=.sql2005;Integrated Security=SSPI;Persist Security Info=False;Initial Catalog=test;Data Source=7085360CB900427");
try
{
sql.Open();
if (sql.State == ConnectionState.Open)
label1.Text = "连接成功!";
}
catch (SqlException S)
{
MessageBox.Show(S.Message);}
finally
{
sql.Close();
sql.Dispose();
}
//asp.net教程连接mssql 2005方法二
private void button_logIn_Click(object sender, EventArgs e)
{
string connectionString = "Data Source=(local);Initial Catalog=system;"
+ "Integrated Security=SSPI;";
SqlConnection connection = new SqlConnection(connectionString);
try
{
connection.Open();
if (connection.State == ConnectionState.Open)
{
SqlCommand selectCmd = new SqlCommand("select * from User where 用户名 = ' " + this.textBox_user.Text + " ' ", connection);
SqlDataReader mysql教程reader = selectCmd.ExecuteReader();
if (mysqlreader.Read())
{
if (this.textBox_password.Text == mysqlreader["密码"].ToString())
{
uiLogin.UserName = this.textBox_user.Text;
uiLogin.Password = this.textBox_password.Text;this.DialogResult = DialogResult.OK;
}
else
{
nLoginCount++;
if (nLoginCount == MAX_LOGIN_COUNT)
{
this.DialogResult = DialogResult.Cancel;
}
else
{
MessageBox.Show("Invalid user name and password!");
this.textBox_user.Focus();
}
}}
else
{
throw new Exception("没有该用户 ");
}
}
}
catch
{
}
connection.Close();
}
//其它的mssql 2005与.net连接方法
使用aspnet_regsql.exe 命令创建数据库教程;
2,连接字符串:
connectionString="Data Source=localhost;
Initial Catalog=apps教程ervicesdb;
Integrated Security=True"
providerName="System.Data.SqlClient"/>
注意这里添加连接字符串的表达式,使用的是集成Windows身份验证(using Windows Integrated Security)的方式
connectionString="Data Source=localhost;
Initial Catalog=appservicesdb;
Integrated Security=True"
providerName="System.Data.SqlClient"/>
另外的一种方式,使用SQL Server的身份认证,可以使用下面的表达式:
providerName="System.Data.SqlClient"
connectionString= "server=myserver;database=Products;uid=salesUser;pwd=sellMoreProducts" />
%>
相关文章
- 污污漫画入口风险警示-合规访问指南与安全指引 12-13
- 海棠文学城网页版官网入口-2025在线网址直达 12-13
- 土豪漫画官方APP免费下载入口-正版无广告畅读保障 12-13
- 歪歪漫画app最新版下载入口-首页畅读无广告直接进 12-13
- SkrBT磁力官网最新入口-skrbt磁力引擎极速版入口 12-13
- 微博热搜网页版极速入口-微博热搜榜官方直达链接 12-13