C#连接sql数据库如何独立运行

qq_38349304 2017-06-04 08:13:14
C#做的程序连接到sql数据库,怎么在不打开数据库的情况下直接运行程序
...全文
640 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
xzxmustwin 2017-11-18
  • 打赏
  • 举报
回复
如果是项目的话 在web.config里配置一下? 不太懂lz的意思
hfj13637261657 2017-10-30
  • 打赏
  • 举报
回复
前端界面可以在Visual Stdio里面做,数据库可以用SQL Server来做,连接数据库代码如下: 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.SqlClient; namespace WindowsFormsApplication1 { public partial class 登录 : Form { public 登录() { InitializeComponent(); this.StartPosition = FormStartPosition.CenterScreen; } private void button1_Click(object sender, EventArgs e) { } private void 登录_Load(object sender, EventArgs e) { SqlConnection sqlConnection = new SqlConnection(); sqlConnection.ConnectionString = "Server=(Local);DataBase=EduBase2015;Integrated Security=sspi"; sqlConnection.Open(); MessageBox.Show ("连接状态:" + sqlConnection.State.ToString() + "\n工作站标识:" + sqlConnection.WorkstationId + "\n服务器地址" + sqlConnection.Database + "\n服务器版本" + sqlConnection.ServerVersion + "\n数据库名称" + sqlConnection.Database); sqlConnection.Close(); MessageBox.Show ("连接状态:"+sqlConnection .State.ToString ()); } } }
xiaoxiangqing 2017-06-08
  • 打赏
  • 举报
回复
没明白楼主的意思。
bluetata 2017-06-07
  • 打赏
  • 举报
回复
引用 3 楼 qq_38349304 的回复:
SQLserver2008 可以实现吗,老师有要求
当然可以,很简单些个 ODBC就可以了
        public SqlConnection GetDBConnection() {

            // string connString = @"Data Source=.\SQLEXPRESS;Initial Catalog=tt;User ID=sa;Password=tiger"; //Sql数据库联接字符串
            string connectionString = "Server=111.111.111.11;DataBase=IBM;Uid=sa;pwd=d!etime1943;";
            //string connectionString = GetConnectionString();
            SqlConnection conn = new SqlConnection(connectionString);  //数据库联接对象

            return conn;
        }
不过正常在项目里一定是配置的服务器或者在配置文件中,LZ平时要好好注意听课啊
qq_38349304 2017-06-06
  • 打赏
  • 举报
回复
SQLserver2008 可以实现吗,老师有要求
二月十六 2017-06-04
  • 打赏
  • 举报
回复
楼主是想数据库服务不启动?还是什么?
卖水果的net 2017-06-04
  • 打赏
  • 举报
回复
这个要做本地缓存了,可以考虑 sqlserver CE 或 sqlite 。

590

社区成员

发帖
与我相关
我的任务
社区描述
提出问题
其他 技术论坛(原bbs)
社区管理员
  • community_281
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧