ConnectionStrings.com - How to connect to SQL Server 2005

本文提供了全面的 SQL Server 2005 连接字符串示例,包括使用标准安全、信任连接、指定实例、提示用户名密码、启用 MARS、加密数据传输等功能,并详细解释了每个选项的作用。
导读:
   Where do youwant to connect?
   What is a connection string?
   Are there any important rulesthat applies to connection strings?
   Why can't my app connect?
  This is a compiled connection strings reference list on how to connect to SQL Server 2005.
   Looking for SQL Server 2005 CE connection strings? They are here >>
   Looking for SQL Server connection strings? They are here >>
   SQL Native Client ODBC Driver
   Standard security
  Driver={SQL Native Client}Server=myServerAddressDatabase=myDataBaseUid=myUsernamePwd=myPassword
  Are you using SQL Server 2005 Express? Don't miss the server name syntax Servername/SQLEXPRESS where you substitute Servername with the name of the computer where the SQL Server 2005 Express installation resides.
   Trusted Connection
  Driver={SQL Native Client}Server=myServerAddressDatabase=myDataBaseTrusted_Connection=yes
  Equivalent key-value pair: "Integrated Security=SSPI" equals "Trusted_Connection=yes"
   Connecting to an SQL Server instance
  The syntax of specifying the server instance in the value of the server key is the same for all connection strings for SQL Server.
  Driver={SQL Native Client}Server=myServerName/theInstanceNameDatabase=myDataBaseTrusted_Connection=yes
   Prompt for username and password
  This one is a bit tricky. First you need to set the connection object's Prompt property to adPromptAlways. Then use the connection string to connect to the database.
  oConn.Properties("Prompt") = adPromptAlwaysDriver={SQL Native Client}Server=myServerAddressDatabase=myDataBase
   Enabling MARS (multiple active result sets)
  Driver={SQL Native Client}Server=myServerAddressDatabase=myDataBaseTrusted_Connection=yesMARS_Connection=yes
  Equivalent key-value pair: "MultipleActiveResultSets=true" equals "MARS_Connection=yes"
  Use ADO.NET 2.0 for MARS functionality. MARS is not supported in ADO.NET 1.0 nor ADO.NET 1.1.
   Encrypt data sent over network
  Driver={SQL Native Client}Server=myServerAddressDatabase=myDataBaseTrusted_Connection=yesEncrypt=yes
   Attach a database file on connect to a local SQL Server Express instance
  Driver={SQL Native Client}Server=./SQLExpressAttachDbFilename=c:/asd/qwe/mydbfile.mdfDatabase=dbnameTrusted_Connection=Yes
  Why is the Database parameter needed? If the named database have already been attached, SQL Server does not reattach it. It uses the attached database as the default for the connection.
   Attach a database file, located in the data directory, on connect to a local SQL Server Express instance
  Driver={SQL Native Client}Server=./SQLExpressAttachDbFilename=|DataDirectory|mydbfile.mdfDatabase=dbnameTrusted_Connection=Yes
  Why is the Database parameter needed? If the named database have already been attached, SQL Server does not reattach it. It uses the attached database as the default for the connection.
   Database mirroring
  If you connect with ADO.NET or the SQL Native Client to a database that is being mirrored, your application can take advantage of the drivers ability to automatically redirect connections when a database mirroring failover occurs. You must specify the initial principal server and database in the connection string and the failover partner server.
  Data Source=myServerAddressFailover Partner=myMirrorServerInitial Catalog=myDataBaseIntegrated Security=True
  There is ofcourse many other ways to write the connection string using database mirroring, this is just one example pointing out the failover functionality. You can combine this with the other connection strings options available.
   SQL Native Client OLE DB Provider
   Standard security
  Provider=SQLNCLIServer=myServerAddressDatabase=myDataBaseUid=myUsernamePwd=myPassword
  Are you using SQL Server 2005 Express? Don't miss the server name syntax Servername/SQLEXPRESS where you substitute Servername with the name of the computer where the SQL Server 2005 Express installation resides.
   Trusted connection
  Provider=SQLNCLIServer=myServerAddressDatabase=myDataBaseTrusted_Connection=yes
  Equivalent key-value pair: "Integrated Security=SSPI" equals "Trusted_Connection=yes"
   Connecting to an SQL Server instance
  The syntax of specifying the server instance in the value of the server key is the same for all connection strings for SQL Server.
  Provider=SQLNCLIServer=myServerName/theInstanceNameDatabase=myDataBaseTrusted_Connection=yes
   Prompt for username and password
  This one is a bit tricky. First you need to set the connection object's Prompt property to adPromptAlways. Then use the connection string to connect to the database.
  oConn.Properties("Prompt") = adPromptAlwaysoConn.Open "Provider=SQLNCLIServer=myServerAddressDataBase=myDataBase
   Enabling MARS (multiple active result sets)
  Provider=SQLNCLIServer=myServerAddressDatabase=myDataBaseTrusted_Connection=yesMarsConn=yes
  Equivalent key-value pair: "MultipleActiveResultSets=true" equals "MARS_Connection=yes"
  Use ADO.NET 2.0 for MARS functionality. MARS is not supported in ADO.NET 1.0 nor ADO.NET 1.1.
   Encrypt data sent over network
  Provider=SQLNCLIServer=myServerAddressDatabase=myDataBaseTrusted_Connection=yesEncrypt=yes
   Attach a database file on connect to a local SQL Server Express instance
  Provider=SQLNCLIServer=./SQLExpressAttachDbFilename=c:/asd/qwe/mydbfile.mdfDatabase=dbnameTrusted_Connection=Yes
  Why is the Database parameter needed? If the named database have already been attached, SQL Server does not reattach it. It uses the attached database as the default for the connection.
   Attach a database file, located in the data directory, on connect to a local SQL Server Express instance
  Provider=SQLNCLIServer=./SQLExpressAttachDbFilename=|DataDirectory|mydbfile.mdfDatabase=dbnameTrusted_Connection=Yes
  Why is the Database parameter needed? If the named database have already been attached, SQL Server does not reattach it. It uses the attached database as the default for the connection.
   Database mirroring
  If you connect with ADO.NET or the SQL Native Client to a database that is being mirrored, your application can take advantage of the drivers ability to automatically redirect connections when a database mirroring failover occurs. You must specify the initial principal server and database in the connection string and the failover partner server.
  Data Source=myServerAddressFailover Partner=myMirrorServerInitial Catalog=myDataBaseIntegrated Security=True
  There is ofcourse many other ways to write the connection string using database mirroring, this is just one example pointing out the failover functionality. You can combine this with the other connection strings options available.
   SqlConnection (.NET)
   Standard Security
  Data Source=myServerAddressInitial Catalog=myDataBaseUser Id=myUsernamePassword=myPassword
  Use serverName/instanceName as Data Source to connect to a specific SQL Server instance.
  Are you using SQL Server 2005 Express? Don't miss the server name syntax Servername/SQLEXPRESS where you substitute Servername with the name of the computer where the SQL Server 2005 Express installation resides.
   Standard Security alternative syntax
  This connection string produce the same result as the previous one. The reason to include it is to point out that some connection string keywords have many equivalents.
  Server=myServerAddressDatabase=myDataBaseUser ID=myUsernamePassword=myPasswordTrusted_Connection=False
   Trusted Connection
  Data Source=myServerAddressInitial Catalog=myDataBaseIntegrated Security=SSPI
   Trusted Connection alternative syntax
  This connection string produce the same result as the previous one. The reason to include it is to point out that some connection string keywords have many equivalents.
  Server=myServerAddressDatabase=myDataBaseTrusted_Connection=True
   Connecting to an SQL Server instance
  The syntax of specifying the server instance in the value of the server key is the same for all connection strings for SQL Server.
  Server=myServerName/theInstanceNameDatabase=myDataBaseTrusted_Connection=True
   Trusted Connection from a CE device
  Often a Windows CE device is not authenticated and logged in to a domain. To use SSPI or trusted connection / authentication from a CE device, use this connection string.
  Data Source=myServerAddressInitial Catalog=myDataBaseIntegrated Security=SSPIUser ID=myDomain/myUsernamePassword=myPassword
  Note that this will only work on a CE device.
   Connect via an IP address
  Data Source=190.190.200.100,1433Network Library=DBMSSOCNInitial Catalog=myDataBaseUser ID=myUsernamePassword=myPassword
  DBMSSOCN=TCP/IP. This is how to use TCP/IP instead of Named Pipes. At the end of the Data Source is the port to use. 1433 is the default port for SQL Server.
   Enabling MARS (multiple active result sets)
  Server=myServerAddressDatabase=myDataBaseTrusted_Connection=TrueMultipleActiveResultSets=true
  Use ADO.NET 2.0 for MARS functionality. MARS is not supported in ADO.NET 1.0 nor ADO.NET 1.1.
   Attach a database file on connect to a local SQL Server Express instance
  Server=./SQLExpressAttachDbFilename=c:/asd/qwe/mydbfile.mdfDatabase=dbnameTrusted_Connection=Yes
  Why is the Database parameter needed? If the named database have already been attached, SQL Server does not reattach it. It uses the attached database as the default for the connection.
   Attach a database file, located in the data directory, on connect to a local SQL Server Express instance
  Server=./SQLExpressAttachDbFilename=|DataDirectory|mydbfile.mdfDatabase=dbnameTrusted_Connection=Yes
  Why is the Database parameter needed? If the named database have already been attached, SQL Server does not reattach it. It uses the attached database as the default for the connection.
   Using an User Instance on a local SQL Server Express instance
  The User Instance functionality creates a new SQL Server instance on the fly during connect. This works only on a local SQL Server 2005 instance and only when connecting using windows authentication over local named pipes. The purpose is to be able to create a full rights SQL Server instance to a user with limited administrative rights on the computer.
  Data Source=./SQLExpressIntegrated Security=trueAttachDbFilename=|DataDirectory|/mydb.mdfUser Instance=true
  To use the User Instance functionality you need to enable it on the SQL Server. This is done by executing the following command: sp_configure 'user instances enabled', '1'. To disable the functionality execute sp_configure 'user instances enabled', '0'.
   Database mirroring
  If you connect with ADO.NET or the SQL Native Client to a database that is being mirrored, your application can take advantage of the drivers ability to automatically redirect connections when a database mirroring failover occurs. You must specify the initial principal server and database in the connection string and the failover partner server.
  Data Source=myServerAddressFailover Partner=myMirrorServerInitial Catalog=myDataBaseIntegrated Security=True
  There is ofcourse many other ways to write the connection string using database mirroring, this is just one example pointing out the failover functionality. You can combine this with the other connection strings options available.
   Asynchronous processing
  A connection to SQL Server 2005 that allows for the issuing of async requests through ADO.NET objects.
  Server=myServerAddressDatabase=myDataBaseIntegrated Security=TrueAsynchronous Processing=True
   SQL Server 2005 specials
   Context Connection
  Connecting to "self" from within your CLR stored prodedure/function. The context connection lets you execute Transact-SQL statements in the same context (connection) that your code was invoked in the first place.
   C#
  using(SqlConnection connection = new SqlConnection("context connection=true"))
  {
  connection.Open();
  // Use the connection
  }
   VB.Net
  Using connection as new SqlConnection("context connection=true")
  connection.Open()
  ' Use the connection
  End Using

本文转自
http://www.connectionstrings.com/?carrier=sqlserver2005
<think>嗯,用户这次问的是IIS 10环境下HTTP 500.19错误的解决方法。从对话历史看,用户已经查阅过三篇相关资料,但似乎还没找到适用方案。用户能明确说出错误代码和服务器版本,说明有一定技术背景,可能是个运维人员或.NET开发者。 用户提供的三个引用其实已经涵盖了主要解决方案方向:[1]提到应用程序池配置和权限问题,[2]强调ASP.NET功能组件安装,[3]则指向AspNetCoreModuleV2模块缺失。不过用户特别注明“不是真正需求”,暗示之前的方案可能不奏效,这很关键。 我注意到用户强调“IIS 10”这个特定环境,需要重点考虑Windows Server 2016/2019的特性。500.19本质是配置错误,但具体到IIS 10可能有三个特殊点:1)对.NET Core的支持机制变化 2)更严格的权限控制 3)配置文件继承逻辑调整。 先从最致命的开始排查比较高效。AspNetCoreModuleV2缺失确实常见于.NET Core部署,但用户没说明应用类型,需要同时准备.NET Framework和Core两套方案。权限问题往往最隐蔽,特别是当应用程序池使用虚拟账户时,很多人会忽略NTFS权限继承中断的情况。 用户情绪似乎有些焦虑(提到“找过很多方案”),回复时要突出“终极”感,把成功率最高的方案放前面。结构上按故障树编排很合适:先解决模块缺失这种硬伤,再处理权限和配置文件软问题,最后是容易遗漏的注册表项。 特别要提醒用户注意Windows更新后的兼容性问题,这是IIS 10的高发场景。案例里有个细节:管理员身份运行DISM命令失败时,可能需要先停止Windows Update服务,这个实战经验值得补充。 </think>针对IIS 10的HTTP 500.19错误(Internal Server Error),以下是经过验证的完整解决方案,按优先级排序执行: --- ### **核心修复步骤** #### 1. **安装缺失的IIS组件**(最常见原因) ```cmd 以管理员身份运行CMD,依次执行: dism /online /enable-feature /featurename:IIS-ISAPIFilter dism /online /enable-feature /featurename:IIS-ISAPIExtensions dism /online /enable-feature /featurename:IIS-NetFxExtensibility45 dism /online /enable-feature /featurename:IIS-ASPNET45 ``` > 📌 适用于.NET Framework应用。执行后重启IIS(`iisreset`)[^2]。 #### 2. **检查AspNetCoreModule模块**(.NET Core应用必做) - 打开IIS → 选中服务器 → **模块**功能 - 确认存在 `AspNetCoreModuleV2` → 若缺失,需安装 [.NET Core Hosting Bundle](https://dotnet.microsoft.com/download/dotnet-core) [^3]。 #### 3. **修复应用程序池身份权限** 1. IIS → **应用程序池** → 选择对应池 → 高级设置 2. 修改**标识(Identity)** 为: - 方案1:`ApplicationPoolIdentity` + 授予网站目录权限 (右键目录 → 安全 → 添加`IIS AppPool\<你的池名>`并赋完全控制) - 方案2:`LocalSystem`(临时测试用) #### 4. **验证Web.config配置** - 检查配置文件是否损坏: ```powershell cd 网站物理路径 aspnet_regiis -pdf "connectionStrings" . ``` - 排查特殊字符(如`<`、`&`需转义为`<`、`&`) - 删除 `<handlers>` 或 `<modules>` 中的重复项 #### 5. **注册IIS元数据库兼容性**(经典方案) ```cmd 以管理员运行CMD: %windir%\Microsoft.NET\Framework64\v4.0.30319\aspnet_regiis -i ``` --- ### **进阶排查** #### ▶ **错误页面定位问题** 查看错误详情页中的 **Config Error** 字段(通常包含具体路径或模块名),例如: - `模块 "AspNetCoreModuleV2" 未注册` → 执行步骤2 - `无法读取配置文件` → 执行步骤4 - `访问路径被拒绝` → 执行步骤3 #### ▶ **清理配置文件继承** 在 `<configuration>` 标签内添加: ```xml <location path="." inheritInChildApplications="false"> <system.webServer> <!-- 自定义配置 --> </system.webServer> </location> ``` #### ▶ **重置IIS配置** ```cmd net stop w3svc cd %windir%\system32\inetsrv appcmd unlock config -section:system.webServer/handlers appcmd unlock config -section:system.webServer/modules net start w3svc ``` --- ### **预防措施** 1. **部署前检查依赖**: - .NET Framework应用:启用IIS的ASP.NET 4.5及相关ISAPI模块 - .NET Core应用:确保Hosting Bundle版本与运行时匹配 2. **权限最小化原则**:避免直接使用`LocalSystem`,推荐`ApplicationPoolIdentity`+精确授权 3. **配置文件备份**:修改Web.config前创建副本 > 💡 **典型场景**:Windows更新后出现此错误?优先执行**步骤1+步骤2**并重启服务器[^1]。 --- **相关问题** 1. 如何区分HTTP 500.19错误是由.NET Framework还是.NET Core应用引发? 2. IIS应用程序池的`ApplicationPoolIdentity`与`NetworkService`有何安全差异? 3. 除了500.19,IIS部署ASP.NET Core还有哪些高发错误及解决方案? 4. Web.config配置继承冲突如何精准定位? [^1]: 综合解决方案框架 [^2]: IIS功能组件修复 [^3]: .NET Core模块依赖
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值