登录
首页 » C# » C# SQL Server数据库连接

C# SQL Server数据库连接

于 2014-07-11 发布
0 181
下载积分: 1 下载次数: 0

代码说明:

 【实例源码】朋友们好,该功能在测试中突然发现,通过Windows身份验证时,服务器IP与数据库值为空的时候,测试连接也会提示连接成功,这个BUG请大家给予帮助,谢谢!using System;using System.Collections.Generic;using System.ComponentModel;using System.Data;using System.Drawing;using System.Linq;using System.Text;using System.Windows.Forms;using System.Data;using System.Data.SqlClient;namespace ConData{    public partial class ConnectionData : Form    {        public ConnectionData()        {            InitializeComponent();        }        private void btnSQLOK_Click(object sender, EventArgs e)        {            string strcon = string.Format("server={0};database={1};uid={2};pwd={3};", this.txtIP.Text.Trim(), txtDataBase.Text.Trim(), txtUser.Text.Trim(), txtPwd.Text.Trim());            try            {                using (SqlConnection con = new SqlConnection(strcon))                {                    con.Open();                    MessageBox.Show("测试成功!");                    con.Close();                }            }            catch (Exception ex)            {                MessageBox.Show(ex.Message);            }        }        private void btnWindowsOK_Click(object sender, EventArgs e)        {            string strCon = string.Format("server={0};database={1};Trusted_Connection=SSPI", txtWindowsIP.Text.Trim(), txtWindowsDB.Text.Trim());            try            {                using (SqlConnection con = new SqlConnection(strCon))                {                    con.Open();                    MessageBox.Show("测试成功!");                    con.Close();                }            }            catch (Exception ex)            {                MessageBox.Show(ex.Message);            }        }    }}

下载说明:请别用迅雷下载,失败请重下,重下不扣分!

发表评论

0 个回复

  • C# 视频播放器(支持avi、mp4等视频文件)
    C# 视频播放器(支持avi、mp4等视频文件)
    2019-06-23下载
    积分:1
  • c#实现的电子钟 例子源码下载
    c#图形编程
    2015-04-22下载
    积分:1
  • 外卖订餐管理系统源码(含数据库脚本)
    运行环境:sql2008,vs2010可,对于初学者能狗很好地学习数据库的操作(增删改查)
    2019-12-20下载
    积分:1
  • sqlite通用类模块
    很多年前写的一个sqlite通用类模块(sqldb.cpp和sqldb.h),全新拿来分享。该资源包含sqlite-amalgamation-3340100源码和测试 testdb.cpp封装该类的目的:统一sqlite数据库接口,以方便windows/linux平台间使用sqlite数据库。该类封装了sqlite3常用操作(可执行 增删改查,事务,创建/增加sql函数,数据库文件压缩,增加sql函数等) 该类的使用方法见 sqldb.h,该头文件有具体的使用示例。用法:1. 生成 libsqlite3.amake -f Makefile_lib2. 生成 测试make3.生成sqlite3 命令行工具gcc -Wall -o sqlite3 shell.c libsqlite3.a -lpthread -ldl
    2021-05-06下载
    积分:1
  • 将txt文件内容读入mysql数据库
    将txt文件内容读入mysql数据库
    2015-06-16下载
    积分:1
  • MES系统源代码
    MES系统源代码
    2021-05-06下载
    积分:1
  • 数据结构习题集.pdf(含答案)
    数据结构习题集.pdf(含答案)
    2020-01-08下载
    积分:1
  • 基于MFC 对话框 的数据库 正删改查简单操作 简单易懂
     _variant_t var; //通过_variant_t和_bstr_t这两个类,就可以方便的把C 类型变量转换成COM中的变量 CString strName,strAge;  // 清空列表框 m_AccessList.ResetContent(); strName=strAge="";  // 在ADO操作中建议语句中要常用try...catch()来捕获错误信息, // 因为它有时会经常出现一些想不到的错误。 try {  if(!m_pRecordset->BOF)//BOF测试当前表文件或指定文件的记录指针是否指向文件首,若是返回真值(.T.),否则返回逻辑假值(.F.)   m_pRecordset->MoveFirst();  else  {   AfxMessageBox(_T("表内数据为空"));   return;  }   // 读入库中各字段并加入列表框中  while(!m_pRecordset->adoEOF)  {   var = m_pRecordset->GetCollect("Name");   if(var.vt != VT_NULL)    strName = (LPCSTR)_bstr_t(var);   var = m_pRecordset->GetCollect("Age");   if(var.vt != VT_NULL)    strAge = (LPCSTR)_bstr_t(var);    m_AccessList.AddString( strName " --> " strAge );    m_pRecordset->MoveNext();  }   // 默认列表指向第一项,同时移动记录指针并显示  m_AccessList.SetCurSel(0);  OnLbnSelchangeListaccess(); } catch(_com_error& e) {  dump_com_error(e); }
    2020-05-29下载
    积分:1
  • C#数据库读取增删改(含sql server数据库)
    C#数据库读取增删改(含sql server数据库)
    2020-05-24下载
    积分:1
  • winform+SQL 的超市管理
    超市管理系统,模拟其他实例制作,界面有点雷同,但是代码不一样。只要用于初学者掌握winform 的控件的应用,SQL的数据库操作
    2019-01-07下载
    积分:1
  • 696516资源总数
  • 106914会员总数
  • 0今日下载