我已经用SQL Server Management Studio创建了一个数据库,我现在想在我的c#应用程序中使用它。我需要连接字符串?
我可以在哪里找到连接字符串,我的数据库存储在哪里?
我需要发表它吗,还是在我的文档里?
using (var conn = new SqlConnection("your connection string to the database"))
如何获取连接字符串?我在哪里可以找到连接字符串复制粘贴到上面的部分?
我如何发布我的数据库,以便Visual Studio可以选择它?然后我就可以拉动这里的连接线了?
在connectionstrings.com上可以找到每个DB提供程序的连接字符串。连接字符串是用某些属性/属性及其值构建的。对于SQL server 2008,它看起来像这样(标准,这是你在这里需要的):
Data Source=myServerAddress;Initial Catalog=myDataBase;User Id=myUsername;Password=myPassword;
在myServerAddress上,写你安装实例的名字(默认是。\SQLEXPRESS for SQL Server Express edition)。初始目录=您的数据库名称,您将在连接后的左侧SSMS中看到它。其余的一切都不言自明。
edit
您需要省略windows身份验证的用户名和密码,并添加Integrated Security=SSPI。
如果您已经安装并设置了MS SQL Server和Management Studio,请转到Visual Studio (Visual Studio而不是SQL Server Management Studio)。
1] In Visual Studio go to Tools -> Connect to Database.
2] Under Server Name Select your Database Server Name (Let the list Populate if its taking time).
3] Under Connect to a Database, Select Select or enter a database name.
4] Select your Database from Dropdown.
5] After selecting Database try Test Connection.
6] If Test Connection Succeeds, Click Ok.
7] In Visual Studio go to View -> Server Explorer.
8] In Server Explorer window, Under Data Connections Select your Database. Right Click your Database -> Click Properties.
9] In Properties window you will see your Connection String.