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" />
%>
《黎明杀机》开发商正开发新的《Serious Sam》游戏 由Devolver发行
超英派遣中心即将登陆Xbox Play Anywhere 深入了解这款独特而备受喜爱的冒险游戏
在《Hunter: The Reckoning – Deathwish》中怎么从猎物蜕变为猎手
《The Expanse: Osiris Reborn》——深入了解玩法 新同伴 封闭测试及发行窗口
Alien Deathstorm 科幻生存与动作结合 打造全新第一人称恐怖混合体验
宝可梦公司已在考虑未来可用口袋妖怪总数达到“或许一万只”
幸存者村庄2
怪可爱的店折相思菜单
怪可爱的店折相思菜单是一款画风治愈的模拟经营佳作,内置折相思菜单解锁多项便利功能
lol电竞经理人手游
lol电竞经理人手游让你可以成为职业的电竞经理人,在游戏中掌控游戏的走向!豪华阵
梦幻奶茶屋小游戏
梦幻奶茶屋是一款主打温馨治愈氛围的休闲经营作品,玩家将化身元气满满的奶茶店店长,
萌宠养成物语无限金币版
萌宠养成物语无限金币版是一款治愈系模拟养成游戏,以可爱卡通画风构建温馨虚拟世界,