Hello
I want to switch from an all Access 2003 database to Access 2010 on the front end and SQL Server 2008 on the back end. Before I spend a lot of time on this I'm trying to see if I can get a few simple things to work.
I'm trying to execute a stored procedure in SQL Server from Access VBA. I have found and modifed the following code from searching on the internet:
When I run this I get an error when it gets to the cnn.open part with an error message of "Login failed for user 'LoginName'.
I have the following questions:
1. Am I taking the correct approach?
2. If I'm using Windows Authentication for the database, how do I include my windows login and password
3. How do I run the stored procedure without including the login and password in the Access VBA code. I assume that this must be possible!
Thank you in advance
Speedball
I want to switch from an all Access 2003 database to Access 2010 on the front end and SQL Server 2008 on the back end. Before I spend a lot of time on this I'm trying to see if I can get a few simple things to work.
I'm trying to execute a stored procedure in SQL Server from Access VBA. I have found and modifed the following code from searching on the internet:
Code:
Private Sub StoredProcedureTest()
Dim cnn As ADODB.Connection
Dim rs As ADODB.Recordset
Set cnn = New ADODB.Connection
cnn.ConnectionString = "Provider=SQLOLEDB;Data Source=COMPUTERNAME\SQLINSTANCENAME;Initial Catalog=DatabaseName;User ID=LoginName;Password=UsersPassword"
cnn.Open
Set rs = New ADODB.Recordset
Set rs = cnn.Execute("EXEC uspSimple")
Debug.Print rs(0), rs(1), rs(2)
rs.Close
Set rs = Nothing
cnn.Close
Set cnn = Nothing
End Sub
When I run this I get an error when it gets to the cnn.open part with an error message of "Login failed for user 'LoginName'.
I have the following questions:
1. Am I taking the correct approach?
2. If I'm using Windows Authentication for the database, how do I include my windows login and password
3. How do I run the stored procedure without including the login and password in the Access VBA code. I assume that this must be possible!
Thank you in advance
Speedball