ConnectString ()函数的介绍

 ConnectString ()函数的介绍:

connectstring 函数主要负责数据库的连接工作

Public Function ConnectString() As String


          'ConnectString = "FileDSN=studentinfo.dsn;UID=sa;PWD=123"     ’通过dsn的方式连接数据库,dsn的用户名和密码


           ConnectString = "Provider=SQLOLEDB;DataSource=192.168.24.174;UserID=sa;Password=123;InitialCatalog=student;Persist Security Info=True" 

'远程连接数据库,provider=sqloledb;----连接数据库的类型。data source="Data Source=192.168.24.17"--------  数据库所在电脑在局域网中的ip地址 ;userid-----用户名,可缩写为uid;password-------密码,可缩写为pwd;initial catalog  通过sql server 数据库直接打开数据库;Persist Security Info——---是否保存安全信息,其实可以简单的理解为"ADO在数据库连接成功后是否保存密码信息",True表示保存,False表示不保存

'ConnectString="Provider=SQLOLEDB;DataSource=192.168.24.174;UserID=sa;Password=123;FileDSN=studentinfo.dsn;Persist Security Info=True"

'远程连接数据库,跟第二个大体形同,不过是使用dsn连接的数据库,在filedsn中直接输入表的名字而不是输入数据库的名字。
  

End Function

这三句字符串都可以连接到数据库,第一个是连接的本机数据库,第二三个是连接局域网的数据库。
主要作用是为打开时的字符串赋值。

原文地址:https://www.cnblogs.com/zhangyuhang3/p/6900899.html