V
vanessa via OfficeKB.com
Can i know why my coding here diplay the error SQL server does not exist or
access denied?
Public Sub GetColNum(ByRef colCount As Integer)
Dim con, recordSet, cmdText
'Create a connection to ms sql server
Set con = CreateObject("ADODB.Connection")
Set recordSet = CreateObject("ADODB.Recordset")
con.Provider = "SqlOleDB"
con.Properties("Data Source").Value = "BBIPROD"
con.Properties("Initial Catalog").Value = "bbiprod"
con.Properties("Integrated Security").Value = "SSPI"
' con.ConnectionString = driver=SQL Server};" &
"server=cindy;uid=Cindy;pwd;database=pubs"
con.Open
'Prepare command string to get number of columns
cmdText = "SELECT count(*) as column_num from information_schema.columns
where table_name = 'tbl_request'"
'Open connection
recordSet.Open cmdText, con
colCount = recordSet.Fields("column_num")
MsgBox ("In Getcolumn() " + Str(colCount))
'Close and set to nothing
recordSet.Close
con.Close
Set recordSet = Nothing
Set con = Nothing
End Sub
Thank you very much oh.....cos i am first time using databace connection.
access denied?
Public Sub GetColNum(ByRef colCount As Integer)
Dim con, recordSet, cmdText
'Create a connection to ms sql server
Set con = CreateObject("ADODB.Connection")
Set recordSet = CreateObject("ADODB.Recordset")
con.Provider = "SqlOleDB"
con.Properties("Data Source").Value = "BBIPROD"
con.Properties("Initial Catalog").Value = "bbiprod"
con.Properties("Integrated Security").Value = "SSPI"
' con.ConnectionString = driver=SQL Server};" &
"server=cindy;uid=Cindy;pwd;database=pubs"
con.Open
'Prepare command string to get number of columns
cmdText = "SELECT count(*) as column_num from information_schema.columns
where table_name = 'tbl_request'"
'Open connection
recordSet.Open cmdText, con
colCount = recordSet.Fields("column_num")
MsgBox ("In Getcolumn() " + Str(colCount))
'Close and set to nothing
recordSet.Close
con.Close
Set recordSet = Nothing
Set con = Nothing
End Sub
Thank you very much oh.....cos i am first time using databace connection.