简体   繁体   English

通过Visual Studio 2010 C#访问sql 2008数据库

[英]Accessing sql 2008 database through visual studio 2010 C#

Hey guys I have what should be a simple question, but I am new to C# so I am having just a little problem. 大家好,我有一个简单的问题,但是我是C#的新手,所以我有一个小问题。 I am using the following connection: 我正在使用以下连接:

SqlConnection conn = new SqlConnection(@"Server=myservername\SQLEXPRESS;Database=Names;");

I have also tried to include user id and password but my login always fails. 我也尝试过输入用户名和密码,但登录始终失败。

I think this is because I am not really sure what username and password to use. 我认为这是因为我不太确定要使用的用户名和密码。

With my sql server I am using windows authentication... if that helps. 与我的SQL Server我正在使用Windows身份验证...如果有帮助。

does anyone know which username and password I should be using? 有谁知道我应该使用哪个用户名和密码? or another way to do this? 或另一种方式来做到这一点?

I have seen that I may need to turn remote access on in my sql settings, can anyone tell me how to do that? 我已经看到我可能需要在sql设置中打开远程访问,任何人都可以告诉我该怎么做吗?

Thanks! 谢谢!

Your connection string should specify that integrated authentication (Windows authentication) has to be used. 您的连接字符串应指定必须使用集成身份验证(Windows身份验证)。 Otherwise it tries to do SQL user/password authentication, which is disabled on the SQL Server by default, and if enabled it doesn't authenticate against Windows users. 否则,它将尝试执行SQL用户/密码身份验证,默认情况下该功能在SQL Server上已禁用,并且如果启用,则不会针对Windows用户进行身份验证。

Server=.\SQLEXPRESS;Database=YourDatabaseName;Integrated Security=SSPI;

Remote access is only required if your application and the SQL Server Express instance aren't on the same machine (which is why the sample connection string here has a . for the server name, which represents the local server). 仅当您的应用程序和SQL Server Express实例不在同一台计算机上时才需要远程访问(这就是为什么示例连接字符串在此处的服务器名称带有. ,该名称代表本地服务器)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 将数据库SQL Server 2008链接到Visual Studio 2010 - Linked database sql server 2008 to visual studio 2010 SQL Server关系中一个非常有趣的问题(SQL Server 2008R2,LINQ To SQL,Visual Studio 2010,C#) - A very interesting problem with SQL Server Relationships (SQL Server 2008R2, LINQ To SQL, Visual Studio 2010, C#) Visual Studio 2008(C#)与SQL Compact Edition数据库错误:26 - Visual Studio 2008 (C#) with SQL Compact Edition database error: 26 将C#项目从Visual Studio 2010降级到Visual Studio 2008 - Downgrade C# Project from visual studio 2010 to visual studio 2008 在尝试使用C#连接到Visual Studio 2010中的本地SQL Server数据库时遇到问题 - Having problems trying to connect to local SQL Server database in Visual Studio 2010 using C# 在Visual Studio 2010 C#中不允许访问数据库文件(SQL Server Compact) - Access to database file not allowed (SQL Server Compact) in Visual Studio 2010 C# 如何在Visual Studio 2010中使用SQL Server 2012数据库打包和部署C#桌面应用程序? - How to package and deploy a C# desktop application with a SQL Server 2012 database in Visual Studio 2010? C#,Visual Studio 2008 - C#, Visual Studio 2008 Visual Studio 2008和C# - Visual Studio 2008 and C# 在Visual Studio 2010 C#中找不到数据库 - Database Couldn't Be Found In Visual Studio 2010 C#
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM