简体   繁体   English

从 C# 应用程序问题连接到 sql server 2005

[英]Connecting to sql server 2005 from C# application problem

I can't get my C# app to connect to the DB .我无法让我的C#应用程序连接到数据库 I have tried numerous ways to connect.我尝试了多种连接方式。 The DB is there.数据库在那里。 And, I can get to it through the sql server.而且,我可以通过 sql 服务器访问它。 However, from within my code, I keep getting the following message:但是,在我的代码中,我不断收到以下消息:

Error accessing the database, a network-related or instance-specific error occurred while establishing a connection to sql server.访问数据库时出错,在建立与 sql 服务器的连接时发生与网络相关或特定于实例的错误。 The sever was not found or was not accessible.服务器未找到或无法访问。 Verify that the instance name is correct and that sql server is configured to allow remote connections.验证实例名称是否正确,并且 sql 服务器配置为允许远程连接。 Provider: sql network interfaces, error 26 - error locating server / instance specified.提供者:sql 网络接口,错误 26 - 错误定位服务器/指定的实例。 then also error occured connection is not open.my data source name is aastha\sqlexpress.for this reson escape sequence not recognised.然后也发生错误连接未打开。我的数据源名称是 aastha\sqlexpress。因为这个 reson 转义序列无法识别。

Here's an easy way to get a valid connectionstring.这是获取有效连接字符串的简单方法。

  1. create a new text document on your desktop在桌面上创建一个新的文本文档
  2. rename its extension from.txt to.udl将其扩展名从.txt 重命名为.udl
  3. use wizard to connect to db使用向导连接到数据库
  4. open.udl file in notepad记事本中的 open.udl 文件
  5. copy string复制字符串
  6. paste into connectionstring粘贴到连接字符串中

Firstly make sure that you can connect to SQL Server using the same credentials of your application.首先确保您可以使用与您的应用程序相同的凭据连接到 SQL 服务器。 Basically make sure that you have Windows and SQL Authentication enabled, IF you are using a SQL username.基本上确保您启用了 Windows 和 SQL 身份验证,如果您使用的是 SQL 用户名。

If you are struggling with connection strings, please go here http://www.connectionstrings.com/ and find the one you need.如果您在连接字符串方面遇到困难,请在此处go http://www.connectionstrings.com/找到您需要的。

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM