简体   繁体   中英

Connecting to sql server 2005 from C# application problem

I can't get my C# app to connect to the DB . I have tried numerous ways to connect. The DB is there. And, I can get to it through the sql server. 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. 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. Provider: sql network interfaces, error 26 - error locating server / instance specified. then also error occured connection is not open.my data source name is aastha\sqlexpress.for this reson escape sequence not recognised.

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
  3. use wizard to connect to db
  4. open.udl file in notepad
  5. copy string
  6. paste into connectionstring

Firstly make sure that you can connect to SQL Server using the same credentials of your application. Basically make sure that you have Windows and SQL Authentication enabled, IF you are using a SQL username.

If you are struggling with connection strings, please go here http://www.connectionstrings.com/ and find the one you need.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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