Wrox Programmer Forums
Go Back   Wrox Programmer Forums > SQL Server > SQL Server 2000 > SQL Server 2000
|
SQL Server 2000 General discussion of Microsoft SQL Server -- for topics that don't fit in one of the more specific SQL Server forums. version 2000 only. There's a new forum for SQL Server 2005.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the SQL Server 2000 section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old July 11th, 2007, 10:18 AM
Authorized User
 
Join Date: Jul 2007
Posts: 14
Thanks: 0
Thanked 0 Times in 0 Posts
Default What's wrong with this code

Hi,
I got an ado code which I am running from Access 2000 front end. THis code is supposed to run a stored procedure on sql server backend by passing parameters to update records. However, I am getting the error message Sql server does not exist or access denied. I am running the sql server on local machine. I know that the userid and password is correct. However, I have no idea why I am having this problem. I would appreciate any help on this matter. Thanks in advance.
CODE:
Private Sub cmdRunProc_Click()

  Dim conn As ADODB.Connection
  Dim cmdUpdate As ADODB.Command
  Dim lngRecs
  Dim strType
  Dim curPercent


Set conn = New ADODB.Connection
Set cmdUpdate = New ADODB.Command

myDSN = "Provider=SQLOLEDB;Data Source=sqlpubs; " & _
              "Initial Catalog=pubs; user id=sa; password=alloyd"

conn.Open myDSN
Set cmdUpdate.ActiveConnection = conn


  ' Get the form values
  strType = Forms!frmParamPassing!txtBookType
  curPercent = Forms!frmParamPassing!txtPercent


  ' Set the properties of the command
  With cmdUpdate
    .ActiveConnection = conn
    .CommandText = "usp_UpdatePrices"
    .CommandType = adCmdStoredProc

    ' Add the parameters
    .Parameters.Append .CreateParameter("@Type", adVarWChar, adParamInput, 12, strType)
    .Parameters.Append .CreateParameter("@Percent", adCurrency, adParamInput, , curPercent)

   ' Execute the command
    .Execute lngRecs, , adExecuteNoRecords
  End With


  ' And finally tell the user what's happened

   MsgBox ("Procedure complete. Records were updated")

  Set conn = Nothing
  Set cmdUpdate = Nothing

End Sub
 
Old July 11th, 2007, 11:28 AM
Friend of Wrox
 
Join Date: Jul 2003
Posts: 599
Thanks: 6
Thanked 3 Times in 3 Posts
Default

Can you try running a simple SELECT query with that DSN to see if that will run?

 
Old July 11th, 2007, 11:32 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 2,480
Thanks: 0
Thanked 1 Time in 1 Post
Default

Jack,

Is that your sql server name is "sqlpubs"? can you try connecting to it using the same username and password with SQL Query Analyser and see if that works just to double check...

Cheers

_________________________
- Vijay G
Strive for Perfection
 
Old July 11th, 2007, 11:34 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 2,480
Thanks: 0
Thanked 1 Time in 1 Post
Default

Not sure if you are missing a SEMI COLON there.
Code:
myDSN = "Provider=SQLOLEDB;Data Source=sqlpubs; " & _
              "Initial Catalog=pubs; user id=sa; password=alloyd;"
              Cheers

_________________________
- Vijay G
Strive for Perfection
 
Old July 11th, 2007, 12:09 PM
Authorized User
 
Join Date: Jul 2007
Posts: 14
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi Folks,
I checked my sql server name and sure enough it did not match the sql server name that I have in code. After changing the name the problem got resolved. Thanks a lot guys and especially to Vijay who pointed out to check the name. The procedure is not changing any value to the backend. I am suspecting it is because I have to send numeric value for the percent that is not being implicitly converted in the code. Not sure. Need more digging to do. Thanks again. Regards.





Similar Threads
Thread Thread Starter Forum Replies Last Post
what's wrong with my code? DyerOppenheimer BOOK: Beginning Ajax with ASP.NET 0 January 7th, 2008 08:46 AM
What's wrong with this code? appleseed C++ Programming 2 November 25th, 2006 08:17 AM
What's wrong with this code? AlDugan XSLT 3 May 19th, 2006 12:06 PM
What is wrong with code? rtr1900 Classic ASP Databases 1 April 3rd, 2006 03:20 AM
what's wrong with this code? miguel.ossa ASP.NET 1.0 and 1.1 Basics 2 January 21st, 2004 11:33 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.