如何设置 SQL Server 连接字符串? [英] How can I set an SQL Server connection string?
本文介绍了如何设置 SQL Server 连接字符串?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在开发一个简单的 C# 应用程序,我想知道这一点:当我将应用程序连接到 PC 上的 SQL Server 时,我知道连接字符串(服务器名称、密码等),但是当我将它连接到另一台 PC,SQL Server 连接字符串不同.SQL Server里有没有自带默认账号可以连接的通用账号?
I'm developing a simple C# application, and 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 comes with a default account that can connect?
我听说过 SQL Server 中的 sa
帐户.什么是sa
?
I have heard about the sa
account in SQL Server. What is sa
?
推荐答案
.NET DataProvider -- 使用用户名和密码的标准连接
using System.Data.SqlClient;
SqlConnection conn = new SqlConnection();
conn.ConnectionString =
"Data Source=ServerName;" +
"Initial Catalog=DataBaseName;" +
"User id=UserName;" +
"Password=Secret;";
conn.Open();
.NET DataProvider -- 可信连接
SqlConnection conn = new SqlConnection();
conn.ConnectionString =
"Data Source=ServerName;" +
"Initial Catalog=DataBaseName;" +
"Integrated Security=SSPI;";
conn.Open();
参考文档.
这篇关于如何设置 SQL Server 连接字符串?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文