存档

2008年3月 的存档

Using ADO save the SQL Server license

2008年3月24日 没有评论

Dim con, rs

‘this is copyright by Yeats.

Private Function OpenConn() As Boolean

On Error GoTo err1

Set con = CreateObject("Adodb.Connection")

Set rs = CreateObject("Adodb.recordset")

Const srv = "."

Const db = "CRONUS"

con.Open "Driver={SQL Server Native Client 10.0};Trusted_Connection=Yes;server=" & srv & ";DATABASE=" & db & ";AutoTranslate=No" ‘–SQL2008

‘con.Open "Driver={SQL Server};Trusted_Connection=Yes;server=" & srv & ";DATABASE=" & db & ";AutoTranslate=No" –SQL 2000

OpenConn = True

Exit Function

err1:

MsgBox "database open error"

OpenConn = False

End Function

Public Sub ListACC()

If OpenConn Then

‘Dim xlSheet As Worksheet, i As Long

‘Set xlSheet = Application.ActiveWorkbook.ActiveSheet

rs.Open "Select * from [$ndo$dbproperty]", con, 1, 1 ‘ if save to SQL Server. Use master.dbo.[$ndo$srvproperty]

Dim mstream

Set mstream = CreateObject("Adodb.Stream")

mstream.Type = 1

mstream.Open

mstream.Write rs.Fields("license").Value

mstream.SaveToFile "C:license.flf", 1

CloseConn

End If

End Sub

Private Sub CloseConn()

con.Close

End Sub

分类: Development 标签: