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.
我是这个。net的新手,请不要介意回答我的简单问题。我正在尝试编写一个windows应用程序,在这里我使用localhost SQLserver进行数据库。
I need to know what is the exact connection string for my localhost, if my server name looks like as below:
我需要知道本地主机的确切连接字符串是什么,如果我的服务器名看起来如下:
Data Source=HARIHARAN-PC\SQLEXPRESS;Initial Catalog=master;Integrated Security=True
数据源= HARIHARAN-PC \ SQLEXPRESS;初始目录=主;综合安全= 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.
连接字符串的格式应该如何?任何人都可以指导我。
I tried like this :
我试过这样:
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();
}
This code errors out at con.Open();
此代码错误在con.Open();
9 个解决方案
#1
26
Using the default instance (i.e., MSSQLSERVER, use the DOT (.))
使用默认实例(即:,MSSQLSERVER,使用点(。)
<add name="CONNECTION_STRING_NAME" connectionString="Data Source=.;Initial Catalog=DATABASE_NAME;Integrated Security=True;" />
#2
8
Choose a database name in Initial Catalog
在初始目录中选择一个数据库名称。
Data Source=HARIHARAN-PC\SQLEXPRESS;Initial Catalog=your database name;Integrated Security=True" ;
看到更多的
#3
3
Try this connection string.
试试这个连接字符串。
Data Source=HARIHARAN-PC\\SQLEXPRESS;Initial Catalog=yourDataBaseName;Integrated Security=True
See this link for more details http://msdn.microsoft.com/en-us/library/system.data.sqlclient.sqlconnection.connectionstring%28v=vs.110%29.aspx
请参阅此链接,了解更多细节:http://msdn.microsoft.com/en- us/library/system.data.sqlclient.sqlconnection.connectionstring%28v/110%29aspx。
#4
2
Do You have Internal Connection or External Connection. If you did Internal Connection then try this:
你有内部连接或外部连接吗?如果你做了内部连接,试试这个:
"Data Source=.\SQLEXPRESS;AttachDbFilename="Your PAth .mdf";Integrated Security=True;User Instance=True";
#5
1
When using SQL Express, you need to specify \SQLExpress instance in your connection string:
在使用SQLExpress时,需要在连接字符串中指定\SQLExpress实例:
string str = "Data Source=HARIHARAN-PC\\SQLEXPRESS;Initial Catalog=master;Integrated Security=True" ;
#6
1
use this connection string :
使用此连接字符串:
Server=HARIHARAN-PC\SQLEXPRESS;Intial Catalog=persons;Integrated Security=True;
rename person with your database name
用数据库名重命名person。
#7
0
Data Source=HARIHARAN-PC\SQLEXPRESS; Initial Catalog=Your_DataBase_name; Integrated Security=true/false; User ID=your_Username;Password=your_Password;
To know more about connection string Click here
要了解有关连接字符串的更多信息,请单击这里。
#8
0
string str = "Data Source=HARIHARAN-PC\\SQLEXPRESS;Initial Catalog=master;Integrated Security=True" ;
#9
0
string str = @"Data Source=HARIHARAN-PC\SQLEXPRESS;Initial Catalog=master;Integrated Security=True" ;
#1
26
Using the default instance (i.e., MSSQLSERVER, use the DOT (.))
使用默认实例(即:,MSSQLSERVER,使用点(。)
<add name="CONNECTION_STRING_NAME" connectionString="Data Source=.;Initial Catalog=DATABASE_NAME;Integrated Security=True;" />
#2
8
Choose a database name in Initial Catalog
在初始目录中选择一个数据库名称。
Data Source=HARIHARAN-PC\SQLEXPRESS;Initial Catalog=your database name;Integrated Security=True" ;
看到更多的
#3
3
Try this connection string.
试试这个连接字符串。
Data Source=HARIHARAN-PC\\SQLEXPRESS;Initial Catalog=yourDataBaseName;Integrated Security=True
See this link for more details http://msdn.microsoft.com/en-us/library/system.data.sqlclient.sqlconnection.connectionstring%28v=vs.110%29.aspx
请参阅此链接,了解更多细节:http://msdn.microsoft.com/en- us/library/system.data.sqlclient.sqlconnection.connectionstring%28v/110%29aspx。
#4
2
Do You have Internal Connection or External Connection. If you did Internal Connection then try this:
你有内部连接或外部连接吗?如果你做了内部连接,试试这个:
"Data Source=.\SQLEXPRESS;AttachDbFilename="Your PAth .mdf";Integrated Security=True;User Instance=True";
#5
1
When using SQL Express, you need to specify \SQLExpress instance in your connection string:
在使用SQLExpress时,需要在连接字符串中指定\SQLExpress实例:
string str = "Data Source=HARIHARAN-PC\\SQLEXPRESS;Initial Catalog=master;Integrated Security=True" ;
#6
1
use this connection string :
使用此连接字符串:
Server=HARIHARAN-PC\SQLEXPRESS;Intial Catalog=persons;Integrated Security=True;
rename person with your database name
用数据库名重命名person。
#7
0
Data Source=HARIHARAN-PC\SQLEXPRESS; Initial Catalog=Your_DataBase_name; Integrated Security=true/false; User ID=your_Username;Password=your_Password;
To know more about connection string Click here
要了解有关连接字符串的更多信息,请单击这里。
#8
0
string str = "Data Source=HARIHARAN-PC\\SQLEXPRESS;Initial Catalog=master;Integrated Security=True" ;
#9
0
string str = @"Data Source=HARIHARAN-PC\SQLEXPRESS;Initial Catalog=master;Integrated Security=True" ;