Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5
Default SQL server does not exist or access denied

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.

--
Message posted via OfficeKB.com
http://www.officekb.com/Uwe/Forums.a...mming/200602/1
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default SQL server does not exist or access denied

Hi Vanessa,

Check the following:

Are you sure that you have an sql server that can be accessed by name "BBIPROD"?
Alternatively, use the IP address of the sql server in this place:
con.Properties("Data Source").Value = "xxx.xxx.xxx.xxx"

Are you sure that you can log on to the database with Integrated Security?
Someone must have configured that for you.
Alternatively, use
con.Properties("User ID").Value =
con.Properties("Password").Value =
Of course, someone must have configured that, too.

For these two points, check with your administrator.

So much for reasons why you get this error.

Cos you are first time using database connection:
There is room for improvement of your VBA code.
For instance, declare variables with the appropriate type they are used for:

Dim con As ADODB.Connection
Dim recordSet As ADODB.Recordset
Dim cmdText As String

Your variables are all of type variant, which is very unfavorable.

In order for ADODB references to work, you must add a
reference to your macro, that is
"Microsoft ActiveX DataObjects 2.x Library"

Other code improvements are imaginable, but first things first.

Regards,
Frank


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.

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5
Default SQL server does not exist or access denied

Hi Frank,

Thank you very much oh....i can access my database now.
i put the wrong name for my SQL server support to be name as "localhost" and
add this field also useful to access my database:
con.Properties("User ID").Value =
con.Properties("Password").Value =

thank you.

regards,
vanessa

--
Message posted via http://www.officekb.com
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Access Denied LE94553 Excel Discussion (Misc queries) 0 December 4th 07 01:29 AM
Access denied richn Excel Discussion (Misc queries) 4 October 30th 07 01:07 AM
Worksheet Access Denied Nick Excel Discussion (Misc queries) 3 July 7th 05 02:48 PM
file delete in Excel receives permission denied by Server 2003 phurst Excel Programming 2 March 10th 05 09:43 PM
462 The remote server machine does not exist? Damon[_2_] Excel Programming 1 December 1st 04 12:17 PM


All times are GMT +1. The time now is 11:13 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"