How to set SQL Server connection string?

2019-01-01 15:37发布

I'm developing a simple C# application, I'd like to know this: When I connect my application to SQL Server on my PC, I know the connection string (server name, password etc.), but when I connect it to another PC, the SQL Server connection string is different. Is there a common account in SQL Server that come with default account that can connect? I have heard about sa account in SQL Server, what is sa?

8条回答
宁负流年不负卿
2楼-- · 2019-01-01 16:00

sa is a system administrator account which comes with sql server by default. As you know might already know, you can use two ways to log in to SQL Server.

screen shot of SQL Server Management Studio

Therefore there are connection strings which suitable for each scenario(such as windows authentication, localdb etc.). Use https://msdn.microsoft.com/en-us/library/jj653752(v=vs.110).aspx#sqlserver to build your connection string. These are XML tags. You just need value of connectionString

查看更多
深知你不懂我心
3楼-- · 2019-01-01 16:06

You can use the connection string as follows and you only need to add your database name.

string connetionString = "Data Source=.;Initial Catalog=DB name;Integrated Security=True;MultipleActiveResultSets=True";
查看更多
登录 后发表回答