csharp 一些常见的连接字符串(在Asp.Net和C#应用程序中非常常用)
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了csharp 一些常见的连接字符串(在Asp.Net和C#应用程序中非常常用)相关的知识,希望对你有一定的参考价值。
//==========CONNECTION STRING==============
string connectionString = @"Server=(local); " +"Database=UniversityManagementDB; " + "Integrated Security=TRUE;";
string _connectionString = WebConfigurationManager.ConnectionStrings["dRetailEntities"].ConnectionString;
<connectionStrings>
<add name="CodeProjectDatabase" connectionString="Server=(local); Database=CodeProjectDatabase; Integrated Security=TRUE;" providerName="System.Data.SqlClient" />
<add name="UniversityConnectionString" connectionString="Server=(local); Database=UniversityManagementDB; Integrated Security=TRUE;" providerName="System.Data.SqlClient"/>
<add name="CodeProjectDatabase" connectionString="Server=(local); Database=CodeProjectDatabase; Integrated Security=TRUE; User ID=mySqlServerUsername;Password=myPassword;" providerName="System.Data.SqlClient" />
<add name="Conn" connectionString="Data Source=192.168.1.25;Initial Catalog=Login;Persist Security Info=True;User ID=sa;Password=example.com" providerName="System.Data.SqlClient" />
<add name="CodeProjectDatabase" connectionString="Server=(local); Database=CodeProjectDatabase; Integrated Security=TRUE; User ID=sa;Password=kawser.cse;" providerName="System.Data.SqlClient" />
<add name="RapidERPEntities" connectionString="metadata=res://*/DataAccess.RapidERP.csdl|res://*/DataAccess.RapidERP.ssdl|res://*/DataAccess.RapidERP.msl;provider=System.Data.SqlClient;provider connection string="data source=KAWSER-PC;initial catalog=RAPIDERP;persist security info=True;user id=sk;password=kawser.cse;MultipleActiveResultSets=True;App=EntityFramework"" providerName="System.Data.EntityClient" />
<add name="RAPIDERPEntities" connectionString="metadata=res://*/DataAccess.RapidERP.csdl|res://*/DataAccess.RapidERP.ssdl|res://*/DataAccess.RapidERP.msl;provider=System.Data.SqlClient;provider connection string="data source=KAWSER-PC;initial catalog=RAPIDERP;persist security info=True;user id=sk;password=kawser.cse;MultipleActiveResultSets=True;App=EntityFramework"" providerName="System.Data.EntityClient" />
// connect to (local) using EF (windows authentication)
<add name="UniversityDBEntities" connectionString="metadata=res://*/Models.UniversityModel.csdl|res://*/Models.UniversityModel.ssdl|res://*/Models.UniversityModel.msl;provider=System.Data.SqlClient;provider connection string="data source=KAWSER-PC;initial catalog=UniversityDB;integrated security=True;MultipleActiveResultSets=True;App=EntityFramework"" providerName="System.Data.EntityClient" />
<add name="UniversityDBEntities" connectionString="metadata=res://*/Models.UniversityModel.csdl|res://*/Models.UniversityModel.ssdl|res://*/Models.UniversityModel.msl;provider=System.Data.SqlClient;provider connection string="data source=(local);initial catalog=UniversityDB;integrated security=True;MultipleActiveResultSets=True;App=EntityFramework"" providerName="System.Data.EntityClient" />
<add name="UniversityDBEntities" connectionString="metadata=res://*/Models.UniversityModel.csdl|res://*/Models.UniversityModel.ssdl|res://*/Models.UniversityModel.msl;provider=System.Data.SqlClient;provider connection string="data source=(local)\SQLEXPRESS;initial catalog=UniversityDB;integrated security=True;MultipleActiveResultSets=True;App=EntityFramework"" providerName="System.Data.EntityClient" />
<add name="simpleAndStandard" connectionString="Data Source=(local); Initial Catalog=StudentDB; User ID=sk; Password=kawser.cse;" providerName="System.Data.SqlClient" />
</connectionStrings>
//========================= LOCAL DB ======================
string GetConnectionStringAbsolutePath = @"Server=(LocalDB)\v11.0;Integrated Security=True;AttachDbFilename=C:\Users\KAWSER\Desktop\Local DB Test\DB_BAK\LocalDB.mdf";
string GetConnectionStringWithRelativePath_toDataDirectory = @"Server=(LocalDB)\v11.0;Integrated Security=True;AttachDbFilename=|DataDirectory|\LocalDB.mdf";
//BEST WAY TO OBTAIN/GET Current/Relative Local Database Directory
public string GetConnectionStringWithRelativePath_toDatabaseFileFromDebugFolder()
{
//string executableLocation = System.Reflection.Assembly.GetExecutingAssembly().Location;
//string relativePath = (System.IO.Path.GetDirectoryName(executableLocation));
//System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().GetName().CodeBase); //NO NEED
string relativePath = Environment.CurrentDirectory;
relativePath += @"\LocalDB.mdf";
return @"Server=(LocalDB)\v11.0;Integrated Security=True;AttachDbFilename="+relativePath;
}
<add name="DefaultConnection" providerName="System.Data.SqlClient" connectionString="Data Source=(LocalDb)\v11.0;Initial Catalog=aspnet-MvcApplication3-20120901000818;Integrated Security=SSPI;AttachDBFilename=|DataDirectory|\aspnet-MvcApplication3-20120901000818.mdf" />
//================================ VELOCITY FINCRIME CONNECTION STRING ========================================
<connectionStrings>
<!--<add name="DefaultConnection" connectionString="data source=(local); initial catalog=FinCrime;persist security info=True;user id=sa;password=aml123;MultipleActiveResultSets=True ; Connect Timeout=10000" providerName="System.Data.SqlClient" />-->
<add name="DefaultConnection" connectionString="data source=192.168.1.208; initial catalog=FinCrime;persist security info=True;user id=kawser;password=kawser;MultipleActiveResultSets=True ; Connect Timeout=10000" providerName="System.Data.SqlClient" />
<add name="SourceConnection" connectionString="Data Source=192.168.1.232/orcl;User ID=C##UCB;Password=aml123; Provider=OraOLEDB.Oracle.1;" />
<add name="DestinationConnection" connectionString="Data Source=192.168.1.208;User ID=sa;Password=aml123;Initial Catalog=AMLTMRS;Provider=SQLNCLI11.1;Auto Translate=False;" />
</connectionStrings>
以上是关于csharp 一些常见的连接字符串(在Asp.Net和C#应用程序中非常常用)的主要内容,如果未能解决你的问题,请参考以下文章