473,386 Members | 1,823 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

Connection string to access SQL Server stored procedure not working

patjones
931 Expert 512MB
Hi,

This may be a SQL Server forum question, but I thought I might try here first. I'm attempting to execute a stored procedure in SQL Server from Access, using VBA. My pertinent code is as follows:

Expand|Select|Wrap|Line Numbers
  1. Dim qrySP As QueryDef
  2. Set qrySP = CurrentDb.CreateQueryDef("SaveGrant")
  3.  
  4. With qrySP
  5.  
  6.     .Connect = "ODBC; DATABASE = XXX; UID = XXX; PWD = XXX; DSN = XXX"
  7.     .ReturnsRecords = False
  8.     .SQL = "EXEC dbo.sproc_SaveGrant " & Nz(DMax("fldGrantID", "dbo_tblPlanning"), 0) + 1 & ",'" & Me.txtProjectName & "'," & CInt(Me.txtYearIssued) & "," & Me.cboGrantSourceType
  9.     .Execute
  10.  
  11.     .Close
  12.  
  13. End With

I'm using 'XXX' here to block out sensitive system information.

This code runs fine, but the problem is that even though I'm specifying the DSN in the connection string, a box pops up back in the Access window asking for it (see my attachment for the screen shot). When I enter the DSN as I have it in the connection string, all goes well and my record is added to the table in SQL Server (the stored procedure is an INSERT with some parameters).

Any idea how I can prevent that box from popping up? Thanks.

Pat
Attached Images
File Type: jpg DSN Entry Box.jpg (59.0 KB, 406 views)
Apr 21 '11 #1
5 4513
pod
298 100+
these are the different connection strings I use for my little projects :)

...hope that helps


Expand|Select|Wrap|Line Numbers
  1.     Dim MSAdbPathAndName As string
  2.     MSAdbPathAndName = "C:\myMSAccessDB.mdb"
  3.     Dim DBS As String
  4.     Dim UID As String 
  5.     Dim PWD As String 
  6.     Dim DBN As String 
  7.     DBS = "websrvr1"
  8.     UID = "user1"
  9.     PWD = "pwd1"
  10.     DBN = "testDB"
  11.  
  12.  
  13.     ORACLE_ConnString = "Provider=msdaora;Data Source=" & DBN & _
  14.                         ";User Id=" & UID & ";Password=" & PWD & ";"
  15.  
  16.     SQL_ConnString = "Provider=SQLOLEDB;DATA SOURCE=" & DBN & _
  17.                         ";UID=" & UID & _
  18.                         ";PWD=" & PWD & _
  19.                         ";Initial Catalog=" & DBN & ";"
  20.  
  21.     MSACCESS_ConnString = "Provider=Microsoft.Jet.OLEDB.4.0; Data Source=" & _
  22.                             MSAdbPathAndName & ";"
Apr 26 '11 #2
patjones
931 Expert 512MB
Hi,

Thanks for replying. I have tried various connection strings, including your SQL_ConnString, to no avail. If I may ask, you have DATA SOURCE and INITIAL CATALOG set to the same thing; but isn't one the server name and the other the database name?

I'm not really sure where to go with this. Thanks.

Pat
Apr 26 '11 #3
pod
298 100+
Sorry for that, you are right, there was a typo there, it happened when I was cleaning up the code, should have left it as is :)
The Data Source is the servername [DBS] and catalog the database name [DBN]

found the string on:
http://www.sqlstrings.com/SQL-Server...on-strings.htm


Expand|Select|Wrap|Line Numbers
  1.  Dim DBS As String 
  2.     Dim UID As String  
  3.     Dim PWD As String  
  4.     Dim DBN As String  
  5.     DBS = "websrvr1" 
  6.     UID = "user1" 
  7.     PWD = "pwd1" 
  8.     DBN = "testDB" 
  9.  SQL_ConnString = "Provider=SQLOLEDB;DATA SOURCE=" & DBS & _
  10.                         ";UID=" & UID & _
  11.                         ";PWD=" & PWD & _
  12.                         ";Initial Catalog=" & DBN & ";"
Apr 27 '11 #4
patjones
931 Expert 512MB
Hi,

A little more information. It turns out that if I use

Expand|Select|Wrap|Line Numbers
  1.     .Connect = "ODBC; DATABASE=database09; UID=GrantsDBUser; PWD=XXX; DSN=J:\BENEFITS\Pat\Access\Grants Watchlist\GrantsDBLink"
  2.     .ReturnsRecords = False
  3.     .SQL = "EXEC dbo.sproc_SaveGrant '" & Me.txtPIN & "', '" & Me.txtProjectName & "', " & CInt(Me.txtYearIssued) & ", " & Me.cboGrantProgram & ", " & Me.txtAwardAmt & ", " & Me.cboBoro & ", '" & Me.txtDescription & "', '" & Me.txtExpiration & "'"

then I get the message 3151 ODBC--connection to 'J:\BENEFITS\Pat\Access\Grants Watchlist\GrantsDBLink' failed. This connection string is what the Access help pages say to use. On the other hand, if I say

Expand|Select|Wrap|Line Numbers
  1.     .Connect = "ODBC;DRIVER=SQL Server Native Client 10.0;SERVER=database09;UID=GrantsDBUser;PWD=XXX;APP=2007 Microsoft Office"

then I get 229[Microsoft][SQL Server Native Client 10.0][SQL Server] The EXECUTE permission was denied on the object 'sproc_SaveGrant', database 'GrantsWatchList', schema 'dbo'. This is the connection string that I get when I hover over one of the SQL Server-linked tables in the Navigation Pane, with the PWD specification added in by me. At least with this one, there is some indication that the code is communicating with SQL Server, whereas with the first one the link fails altogether.

I've tried numerous other connection strings, to no avail. Any ideas, anyone? This is driving me up a wall. Thanks.

Pat
Apr 27 '11 #5
patjones
931 Expert 512MB
Hi,

Got it working with the second connection string pointed out in my previous post:

Expand|Select|Wrap|Line Numbers
  1. .Connect = "ODBC;DRIVER=SQL Server Native Client 10.0;SERVER=database09;UID=GrantsDBUser;PWD=XXX;APP=2007 Microsoft Office"

In order to fix the issue of not having EXECUTE permission, as mentioned in my previous reply, I had to go into SQL Server Management Studio > Database Properties > Permissions, and grant Execute permission to the user GrantsDBUser. It then works.

What is interesting though is that while it shows sensitivity to changing the DRIVER or SERVER parameters, I can change UID to anything and it still works. Not sure how this is possible, but at least I have a basic level of functionality now.

Pat
Apr 28 '11 #6

Sign in to post your reply or Sign up for a free account.

Similar topics

4
by: mingzhen | last post by:
Hi, I have a problem here when I code stored procedure to manipulate data in database. My idea is that if I can save all data I get in some arrays I should be able to manipulate the arrays...
4
by: Lauren Quantrell | last post by:
Is there anyway to extract part of a string in a stored procedure using a parameter as the starting point? For example, my string might read: x234y01zx567y07zx541y04z My Parameter is an nvarchar...
1
by: David C. Allen | last post by:
I am trying to debug an SQL Server Stored Procedure form VS.NET 2003. I have a break point set in the SP code but it is not being hit. When I hold the pointer over the line it says that it will not...
3
by: Niyazi | last post by:
Hi, Me again. I want to create a SQL Server StoreProcedure and I want to access it with ADO.NET. I am using VB.NET. Creating StoreProcedure it was easy but my question is this. I have table...
6
by: fumanchu | last post by:
I've got to let end users (really just one person) load billing batch files into a third party app table. They need to specify the billing cycle name, the batch name, and the input file name and...
2
by: honcho | last post by:
Hello, Does anyone have an example of an SQL Server stored procedure that updates a record, where one of its field is of type "text"? My procedure is /* ** Update the client note and...
4
by: Mr Not So Know It All | last post by:
im new to SQL Server and ASP.Net. Here's my problem. I have this SQL Server stored procedure with an input parameter and output parameter CREATE PROCEDURE . @in_rc varchar(8) @out_eList...
1
hariharanmca
by: hariharanmca | last post by:
How to Shift or Copy Data from Sqlserver to MS Access using Stored procedure I am passing the clint MS Access file path in that i want to insert or update data in that MS Access file using...
1
by: seyyadri | last post by:
Hi, I want the data in excel, pulled from SQL server stored procedure. The SQL SP has the parameters. when we open/refresh the excel it should prompt the user to enter the parameters (dynamically),...
2
by: mfaisalwarraich | last post by:
hi everybody, im new in vb.net. im trying to make a win form application using visual studio 2008 express edition (which is free to download and install). i have installed a ms sql server 2005...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.