数据库链接问题
本来一直很好用的,我误删了什么东西后每次链接就会提示
在建立与服务器的链接时出错,在链接到sql server 2005时,在默认的设置 sqlserver 不允许进行远程连接可能会导致次失败(provider:共享内存提供程序error 40-无法打开到 sql server的链接)
该怎么改呢,我用的是sql2000数据库,安装vs2005它给我加了装了个sql2005
[解决办法]
Dim sqlConnection1 As SqlClient.SqlConnection
Dim strConnect As String=”data source=服务器名;initial catalog=数据库名;user id=sa;password=;”
sqlConnection1=New System.Data.SqlClient.SqlConnection(strConnect)
sqlConnection1.open ‘打开数据库
sqlConnection1.close
[解决办法]
'设置连接串...
Dim strConnString as String
strConnString= "Provider=SQLOLEDB;Persist Security Info=True;Data Source=192.168.0.245;Initial Catalog=pubs;User ID=saa;Password=liang; "
'创建对象ADOConnection
Dim objConn as OleDbConnection
objConn = New OleDbConnection
'设置ADOCOnnection对象的连接串
objConn.ConnectionString = strConnString
objConn.Open() '打开数据链路
'创建SQL字符串
Dim strSQL as String = "SELECT * FROM authors "
'创建对象ADODatasetCommand 和Dataset
Dim objDSCommand as OleDbCommand
Dim objDataset as Dataset = New Dataset
objDSCommand = New OleDbCommand(strSQL, objConn)
'填充数据到Dataset
'并将数据集合命名为 "Author Information "
objDSCommand.Fill(objDataset, "Author Information ")
objConn.Close() '关闭数据链路
objConn = Nothing '清除对象
Authors.DataSource = _
objDataset.Tables( "Author Information ").DefaultView
Authors.DataBind()