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: - Dim qrySP As QueryDef
-
Set qrySP = CurrentDb.CreateQueryDef("SaveGrant")
-
-
With qrySP
-
-
.Connect = "ODBC; DATABASE = XXX; UID = XXX; PWD = XXX; DSN = XXX"
-
.ReturnsRecords = False
-
.SQL = "EXEC dbo.sproc_SaveGrant " & Nz(DMax("fldGrantID", "dbo_tblPlanning"), 0) + 1 & ",'" & Me.txtProjectName & "'," & CInt(Me.txtYearIssued) & "," & Me.cboGrantSourceType
-
.Execute
-
-
.Close
-
-
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
5 4513
these are the different connection strings I use for my little projects :)
...hope that helps -
Dim MSAdbPathAndName As string
-
MSAdbPathAndName = "C:\myMSAccessDB.mdb"
-
Dim DBS As String
-
Dim UID As String
-
Dim PWD As String
-
Dim DBN As String
-
DBS = "websrvr1"
-
UID = "user1"
-
PWD = "pwd1"
-
DBN = "testDB"
-
-
-
ORACLE_ConnString = "Provider=msdaora;Data Source=" & DBN & _
-
";User Id=" & UID & ";Password=" & PWD & ";"
-
-
SQL_ConnString = "Provider=SQLOLEDB;DATA SOURCE=" & DBN & _
-
";UID=" & UID & _
-
";PWD=" & PWD & _
-
";Initial Catalog=" & DBN & ";"
-
-
MSACCESS_ConnString = "Provider=Microsoft.Jet.OLEDB.4.0; Data Source=" & _
-
MSAdbPathAndName & ";"
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
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 -
Dim DBS As String
-
Dim UID As String
-
Dim PWD As String
-
Dim DBN As String
-
DBS = "websrvr1"
-
UID = "user1"
-
PWD = "pwd1"
-
DBN = "testDB"
-
SQL_ConnString = "Provider=SQLOLEDB;DATA SOURCE=" & DBS & _
-
";UID=" & UID & _
-
";PWD=" & PWD & _
-
";Initial Catalog=" & DBN & ";"
Hi,
A little more information. It turns out that if I use - .Connect = "ODBC; DATABASE=database09; UID=GrantsDBUser; PWD=XXX; DSN=J:\BENEFITS\Pat\Access\Grants Watchlist\GrantsDBLink"
-
.ReturnsRecords = False
-
.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 - .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
Hi,
Got it working with the second connection string pointed out in my previous post: - .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
Sign in to post your reply or Sign up for a free account.
Similar topics
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...
|
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...
|
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...
|
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...
|
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...
|
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...
|
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...
|
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...
|
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),...
|
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...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
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$) {
}
...
|
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...
|
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...
|
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
|
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...
|
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...
|
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...
|
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...
| |