asp.net C#中SqlServer连接字符串

作者:袖梨 2022-06-25

ODBC:连接数据库

 代码如下 复制代码

Driver={SQL Server}; Server=rousecms.hostedresource.com; Database=rousecms; Uid=rousecms; Pwd='your password';

 
OLE DB, OleDbConnection (.NET):连接数据库

 代码如下 复制代码

Provider=sqloledb; Data Source=rousecms.hostedresource.com; Initial Catalog=rousecms; User ID=rousecms; Password='your password';


Provider=SQLOLEDB;Server=METEOR-PC;DATABASE=RouseCMS;UID=sa;PWD=123456

 
SqlConnection (.NET):

 代码如下 复制代码

 
Data Source=rousecms.hostedresource.com; Initial Catalog=rousecms; User ID=rousecms; Password='your password';

在.net中连接

 代码如下 复制代码

System.Data
System.Data.SqlClient

public void Page_Load()
{
  SqlConnetion myConnetion=new SqlConnetion();
  myConnetion.SqlConnetionString="user id=sa;password=***;initial catalog=testDataBase;data source=mySqlServer";
  myConnetion.Open();
}

 代码如下 复制代码

connStr="data source='aaa';uid=;pwd=;database='sss'"
data source 数据源
uid 用户名
pwd 密码
database 数据库名;
2,如果是winnt验证模式 connStr要加上Trusted_Connection=yes
3,远程连接和本地连接,只要修改data source即可

相关文章

精彩推荐