Wednesday, March 28, 2012

How to connection MS Access Porject (.adp) with SQL server?

Hi all,
I got the question, how can i connection MS Access Project to a SQL Server
in vba in runtime.
The situation is i create a new MS Access Project, it's didn't have any
connection with any SQL-server. It's just consist a couple of form. What i
want is that user can via an inlog form to get in the database. The
informations about the server...etc is save in the code. The user just need
to give the SQL-login and password. My code to make the connection is as
follow.
'----
--
Function GetADPConnection(strServername, strDBName As String, Optional strUN
As String, _ Optional strPW As String)
Dim strConnect as string
strConnect = "Provider=SQLOLEDB" & _
";Data Source = \10.0.0.4\" & strServername & _
";Initial Catalog =" & strDBName
strConnect = strConnect & ";UID=" & strUN
strConnect = strConnect & ";PWD=" & strPW
Application.CurrentProject.OpenConnection strConnect
End Function
'----
--
It doesn't seems to work and i get the following error messagge:
[DBNETLIB][ConnectionOpen (Connect()).]SQL Server does not exist or
access
denied.
Can anyone help?
Best Regards,
PatData source should be in the form of:
Servername (or IP - 10.0.0.20)
For a named instance, you can use:
Servername\InstanceName
You can find sample connection strings at:
http://www.carlprothman.net/Default.aspx?tabid=81
-Sue
On Thu, 6 Apr 2006 07:49:02 -0700, Pat
<Pat@.discussions.microsoft.com> wrote:

>Hi all,
>I got the question, how can i connection MS Access Project to a SQL Server
>in vba in runtime.
>The situation is i create a new MS Access Project, it's didn't have any
>connection with any SQL-server. It's just consist a couple of form. What i
>want is that user can via an inlog form to get in the database. The
>informations about the server...etc is save in the code. The user just need
>to give the SQL-login and password. My code to make the connection is as
>follow.
>'----
--
>Function GetADPConnection(strServername, strDBName As String, Optional strU
N
>As String, _ Optional strPW As String)
>Dim strConnect as string
> strConnect = "Provider=SQLOLEDB" & _
> ";Data Source = \10.0.0.4\" & strServername & _
> ";Initial Catalog =" & strDBName
> strConnect = strConnect & ";UID=" & strUN
> strConnect = strConnect & ";PWD=" & strPW
> Application.CurrentProject.OpenConnection strConnect
>End Function
>'----
--
>It doesn't seems to work and i get the following error messagge:
>[DBNETLIB][ConnectionOpen (Connect()).]SQL Server does not exist or
access
>denied.
>Can anyone help?
>Best Regards,
>Pat
>sql

No comments:

Post a Comment