本地服务器的SQL连接字符串 [英] Sql connection-string for localhost server

查看:65
本文介绍了本地服务器的SQL连接字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是该.NET的新手,请介意回答我的简单问题。
我试图编写一个Windows应用程序,在其中我使用本地SQL Server作为数据库。

I am newbie in this .NET and please don't mind in answering my simple question. I am trying to write a windows application, where in I am using a localhost SQLserver for database.

我需要知道确切的连接字符串是什么我的本地主机,如果我的服务器名称如下所示:

I need to know what is the exact connection string for my localhost, if my server name looks like as below:



数据源= HARIHARAN-PC\SQLEXPRESS ; Initial Catalog = master; Integrated Security = True

Data Source=HARIHARAN-PC\SQLEXPRESS;Initial Catalog=master;Integrated Security=True


我需要给它与连接相同的名称字符串,或此语法有误。

should i need to give this same as connection string, or is something wrong in this syntax.

我尝试打开连接。
我在打开连接时看到错误。

whn i try to open my connection. I am seeing error in opening connection.

连接字符串的格式应如何?

How the format of connection string should be? any one please guide me.

我尝试过这样:

 private void button1_Click(object sender, EventArgs e)
    {
        string str = "Data Source=HARIHARAN-PC\SQLEXPRESS;Initial Catalog=master;Integrated Security=True" ; 
        SqlConnection con = new SqlConnection(str);
        SqlCommand cmd = new SqlCommand();
        SqlDataReader r;

        cmd.CommandText = "SELECT * from Table1";
        cmd.CommandType = CommandType.Text;
        cmd.Connection = con;

        con.Open();

        r = cmd.ExecuteReader();

        con.Close();


    }

此代码在con.Open时出错();

This code errors out at con.Open();

推荐答案

使用默认实例(即MSSQLSERVER,使用DOT(。))

Using the default instance (i.e., MSSQLSERVER, use the DOT (.))

<add name="CONNECTION_STRING_NAME" connectionString="Data Source=.;Initial Catalog=DATABASE_NAME;Integrated Security=True;" />

这篇关于本地服务器的SQL连接字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆