VS2010 Database Connectivity Issues

Source: Internet
Author: User
Tags connectionstrings

I wrote a small table with SQL Server 2008, ran vs before I chose the tool-connect to the database, and then chose the name of that table. After running the following error prompt, ask is where the problem?

There is a problem with the database connection version. It would be nice to change the code of the credit database version in vs.

Server=.; DATABASE=JTJ; User Id=sa; password=

Changed to the data source=.\\sqlexpress;initial CATALOG=JTJ; User Id=sa; password=

The following can not be seen.

1. Open the Sql2005 remote connection function, open the method as follows:
Configuration Tools->sql Server Surface area Configurator, services and connections, surface area Configuration, open the Database Engine node under the MSSQLSERVER node, select Remote Connection, and then choose to use the tcp/ IP and Named pipes ", OK to restart the database service.

2. Change the login settings to: SQL Server and Windows authentication mode, as follows:
SQL Server Management Studio Manager->windows Authentication connection Server, Object Explorer, select your data server, right-click Properties--Security->sql server and Windows authentication mode is selected.
3. Set up a user name and password in SQL Server mode, as follows:
(1) SQL Server Management Studio Manager->windows Authentication connection Server, Object Explorer, select your data server on the expand Server, login name, On the SA account, right-click Select Page, select General, change the password for the sa login account. This sets up a user named SA with the password: sa123456.
(2) "Select Page" SELECT Status--login modify to enable
4. Database connection string
Database connection string There are several kinds of, I believe you have seen, have been dizzy
Data source=.\sqlexpress;initial Catalog=northwind; User Id=sa; password=sa123456
Data source= server name \sqlexpress;initial catalog=northwind; User Id=sa; password=sa123456
Data source=localhost\sqlexpress;initial Catalog=northwind; User Id=sa; password=sa123456
Data Server=.;i Nitial Catalog=northwind; User Id=sa; password=sa123456
Data source= server name; Initial catalog=northwind; User Id=sa; password=sa123456
......
What kind of right? This is related to the database version, and if it is a SQL Server 2005 Express version, you must have "\sqlexpress". And if the string is defined as a variable, VS2005 will also add a red wavy line underneath "\" to suggest that "\s is an unrecognized escape sequence", so if the string is defined as a variable, it should be written server=.\\sqlexpress
5. Registering the SQL Server database
Run the "aspnet_regsql" directive under the path "C:\Windows\Microsoft.NET\Framework\v2.0.50727" and the ASP. NET SQL Server Setup Wizard Wizards appears. The SQL Server registration interface will appear after pressing the next two consecutive steps, and the database parameters you want to register are registered. After registering, you will have more tables () in your database:

6. Setting the database connection string
Open iis-> on the default Web site or the virtual directory where the Web site is located, right-click Properties, select the ASP. Edit configuration, and on the General tab edit the LocalSqlServer database connection string:
Data server=.\sqlexpress;initial Catalog=northwind; User Id=sa; password=sa123456
7. Setting up the Web. config file
Add the following program to the Web. config file:
<connectionStrings>
<add name= "LocalSqlServer" connectionstring= "Data source=.\sqlexpress;initial catalog=northwind; User Id=sa; password=sa123456 "providername=" System.Data.SqlClient "/>
</connectionStrings>

VS2010 Database Connectivity Issues

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.