简体   繁体   中英

ASP.NET MVC Database ConnectionString Explanation

In one of my ASP.NET MVC projects, the connectionString is given as follows in the web.config file.

<connectionStrings>
    <add name="db_connection" 
    connectionString="Data Source=ASTRONOMY
    Initial Catalog=GALLERIA;
    user=sa_galleria;
    password=Tyrr#!!55u;
    providerName="" />
</connectionStrings>

This connection string is supposed to work on Microsoft SQL Server (Full Editions).

I found that this connection setting is a little different than what the MSDN article here explains. Especially, the following differences exist:

  1. Is the connectionStrings configuration case-insensitive?
  2. What does ASTRONOMY refer to here? (as Data Source )
  3. Can User Id be shortened as user ?
  4. What value is set for providerName if it's omitted or has an empty value?

Thank you for your clarification.

1.Is the connectionStrings configuration case-insensitive?

Some parts are, such as password

2.What does ASTRONOMY refer to here? (as Data Source)

That's the servername and instance eg SERVER\\SQLEXPRESS

3.Can User Id be shortened as user?

Nope ok, yes UID see comments

4.What value is set for providerName if it's omitted or has an empty value?

NET Framework Data Provider see SQL providerName in web.config

Have a look at

https://connectionstrings.com/sql-server/

Data Source=ASTRONOMY

Data Source -or- Server -or- Address -or- Addr -or- Network Address

The name or network address of the instance of SQL Server to which to connect. The port number can be specified after the server name: server=tcp:servername, portnumber. When specifying a local instance, always use (local). To force a protocol, add one of the following prefixes: np:(local), tcp:(local), lpc:(local)

ADO.NET 2.0 does not support asynchronous commands over shared memory for SQL Server 2000 or earlier. However, you can force the use of TCP instead of shared memory, either by prefixing tcp: to the server name in the connection string, or by using localhost.


Initial Catalog=GALLERIA;

Initial Catalog -or- Database

The name of the database.


user=sa_galleria;

The SQL Server login account.


password=Tyrr#!!55u;

Password -or- Pwd

The password for the SQL Server account logging on. Not used with (the strongly recommended) 'Integrated Security=true' option. Case sensitive


providerName=""

System.Data.SqlClient is the .NET Framework Data Provider for SQL Server. ie .NET library for SQL Server. In the web.config you should have the System.Data.SqlClient as the value of the providerName attribute. It is the .NET Framework Data Provider you are using.


Source: https://www.connectionstrings.com/all-sql-server-connection-string-keywords/

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