标签: connection-string

ASP.NET:如何从web.config ConnectionString创建连接?

如何根据提供者名称构建DbConnection ?

样本提供者的名称小号

  • System.Data.SqlClient的
  • System.Data.OleDb
  • System.Data.Odbc
  • FirebirdSql.Data.FirebirdClient

我有连接字符串存储在我的IIS服务器的web.config文件中:

<connectionStrings>
  <add name="development"
        connectionString="Provider = IBMDA400; Data Source = MY_SYSTEM_NAME; User Id = myUsername; Password = myPassword;" 
        providerName="System.Data.OleDb" />
  <add name="live" 
        connectionString="usd=sa;pwd=password;server=deathstar;" 
        providerName="System.Data.Odbc" />
  <add name="testing" 
        connectionString="usd=sa;pwd=password;server=deathstar;" 
        providerName="System.Data.SqlClient" />
  <add name="offline"
        connectionString="Server=localhost;User=SYSDBA;Password=masterkey;Charser=NONE;Database=c:\data\mydb.fdb"
        providerName="FirebirdSql.Data.FirebirdClient"/>
Run Code Online (Sandbox Code Playgroud)

您可以看到他们都使用不同的提供商.当我需要创建连接时,我必须知道要创建什么样的DbConnection,例如:

  • 的SqlConnection
  • 的OleDbConnection
  • OdbcConnection
  • FbConnection

connectionStrings条目包含providerName,但这些不是DbConnection后代类的名称,但似乎是名称空间

如何根据字符串providerName转换构造DbConnection ?


public DbConnection GetConnection(String connectionName)
{
    //Get the connectionString infomation
    ConnectionStringSettings cs = 
          ConfigurationManager.ConnectionStrings[connectionName];
    if (cs == null)
       throw new ConfigurationException("Invalid connection name …
Run Code Online (Sandbox Code Playgroud)

provider ado.net connection-string web-config dbconnection

10
推荐指数
1
解决办法
2万
查看次数

经典ASP - 使用Windows身份验证的SQL Server 2008连接字符串

这应该非常简单,但我无法使用Windows身份验证为SQL Server 2008的本地副本提供有效的连接字符串.我已经尝试使用数据链接属性工具来创建连接字符串,它没有连接问题,但当我复制粘贴生成的字符串到我的ADODB.Connection对象的ConnectionString属性时,我得到各种有趣和不同的错误.

Set conn = Server.CreateObject("ADODB.Connection")
conn.ConnectionString = "SQLNCLI10.1;Integrated Security=SSPI;Persist Security Info=False;Initial Catalog=climb4acure;Data Source=(local);"
Run Code Online (Sandbox Code Playgroud)

Microsoft OLE DB Service Components (0x80040E21) Multiple-step OLE DB operation generated errors. Check each OLE DB status value, if available. No work was done.

我尝试了各种类似的连接字符串,但我找不到一个可以使用Windows身份验证的连接字符串.有人能指出我正确的方向吗?

谢谢!

database connection-string ado asp-classic sql-server-2008

10
推荐指数
2
解决办法
5万
查看次数

Excel VBA - 使用可信连接(无uid/pwd)连接到sql

有没有办法让Excel使用当前用户的网络Windows身份验证(可信连接/集成安全性)连接到Sql Server?我不想依赖sql登录或在我的代码中有一个uid /密码.

sql excel vba connection-string adodb

10
推荐指数
2
解决办法
7万
查看次数

在运行时更改数据集连接字符串

我有ac生成的数据集.如何更改连接字符串,以便将数据集与另一个(结构相同但填充程度不同的)数据库一起使用?这必须在运行时发生,因为我不知道编译时的服务器或数据库名称.我正在使用c#2.0.

c# connection-string runtime dataset

10
推荐指数
2
解决办法
2万
查看次数

如何从另一个项目访问连接字符串

我在Visual Studio 2010中的解决方案中有两个项目.
项目1包含app.config一个ConnectionString.

如何ConnectionString从Project 2 访问它?

由于它们都使用相同的ConnectionString,我宁愿在我的解决方案中只有一个实例.

.net c# connection-string

10
推荐指数
1
解决办法
9752
查看次数

如何在web.config中增加执行sql查询的时间

当我在Web应用程序中运行查询时,我得到一个null值.SQL Management Studio中直接相同的查询返回结果.

我认为问题是暂停.如何在Web应用程序中增加执行查询的时间?在我的web.config:中connectionstring,没有超时代码.如果我在那里选择超时,会影响我系统的其他部分吗?

sql asp.net connection-string web-config

10
推荐指数
2
解决办法
10万
查看次数

如何安全地存储和访问连接字符串详细信息?

我目前正在开发一个ASP.NET MVC网站,我已经达到了一个需要将数据库集成到网站中的地步.

通常我只是将相应的连接字符串添加到Web.config文件中:

<add name="MainDB" 
    connectionString="Server=localhost; Database=TopSecretData; User Id=Joe;
    password=password" providerName="System.Data.SqlClient" />
Run Code Online (Sandbox Code Playgroud)

但是,如果我将用户ID和密码保留在其中Web.config,尤其是在源代码管理下,则显然存在明显的安全漏洞.

简而言之:如何在不公开显示连接字符串详细信息的情况下存储它?

c# connection-string database-connection asp.net-mvc-3

10
推荐指数
1
解决办法
8942
查看次数

从web.config获取多个连接字符串

如何通过C#中的代码从web.config获取所有连接字符串的名称?

我试过这个:

System.Configuration.Configuration webConfig = System.Web.Configuration.WebConfigurationManager.OpenWebConfiguration("~");
ConnectionStringsSection x = webConfig.ConnectionStrings;
string here = x.SectionInformation.Name;
Run Code Online (Sandbox Code Playgroud)

c# connection-string web-config

10
推荐指数
2
解决办法
1万
查看次数

如何读取.net 4.5中的连接字符串

如何从web.config文件中读取4.5 .net框架中的连接字符串的值?

我正在使用system.configuration,我有一个引用和一个using语句,但在此之后唯一要使用的是.ConfigurationSettings.Appsettings.

没有连接字符串设置.

.net c# vb.net connection-string web-config

10
推荐指数
1
解决办法
2万
查看次数

Azure:Web.config连接字符串'参数不能为null或为空

当我尝试发布一个azure应用程序时,我收到此错误.C:\ Program Files(x86)\ MSBuild\Microsoft\VisualStudio\v14.0\Web\Microsoft.Web.Publishing.targets(4283,5):错误:'ibasis_Data_Transfer.mytestdbEntities-Web.config连接字符串'参数不能为空或空.

我的App.Config有一个连接字符串.例如

 <add name="mytestdbEntities" connectionString="metadata=res://*/mytestappModel.csdl|res://*/mytestappModel.ssdl|res://*/mytestappModel.msl;provider=System.Data.SqlClient;provider connection string=&quot;data source=tcp:srv-mytestapp-home.database.windows.net,1433;initial catalog=mytestdb;persist security info=True;user id=blabla;password=blabla;MultipleActiveResultSets=True;App=EntityFramework&quot;" providerName="System.Data.EntityClient" />
Run Code Online (Sandbox Code Playgroud)

不知道在哪里开始寻找解决方案,因为网络上任何与天蓝色相关的错误都没有提到.

ibasis - Web Deploy.pubxml

<?xml version="1.0" encoding="utf-8" ?>
<!--
This file is used by the publish/package process of your Web project. You can customize the behavior of this process
by editing this MSBuild file. In order to learn more about this please visit http://go.microsoft.com/fwlink/?LinkID=208121. 
-->
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
  <PropertyGroup>
    <WebPublishMethod>MSDeploy</WebPublishMethod>
    <PublishProvider>AzureWebSite</PublishProvider>
    <LastUsedBuildConfiguration>Release</LastUsedBuildConfiguration>
    <LastUsedPlatform>Any CPU</LastUsedPlatform>
    <SiteUrlToLaunchAfterPublish>http://ibasis.azurewebsites.net</SiteUrlToLaunchAfterPublish>
    <LaunchSiteAfterPublish>False</LaunchSiteAfterPublish>
    <MSDeployServiceURL>ibasis.scm.azurewebsites.net:443</MSDeployServiceURL>
    <DeployIisAppPath>ibasis</DeployIisAppPath>
    <SkipExtraFilesOnServer>True</SkipExtraFilesOnServer>
    <MSDeployPublishMethod>WMSVC</MSDeployPublishMethod>
    <UserName>$ibasis</UserName>
    <_SavePWD>True</_SavePWD> …
Run Code Online (Sandbox Code Playgroud)

connection-string azure azure-deployment azure-webjobs visual-studio-2015

10
推荐指数
2
解决办法
6214
查看次数