473,413 Members | 1,801 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,413 software developers and data experts.

Connecting to SQL Server using domain account

Hi.

I am asked to connect to SQL server to retrieve a record from its table from MS Access directly.

Given the following lines of code, I am not able to connect to the SQL server because the login id used is a domain account not sql server login id .


Private Sub Command0_Click()

Dim lobjCn As New ADODB.Connection

With lobjCn
.ConnectionString = "Provider=sqloledb;Server=LDNPCM05421V05A,10501;Da tabase=TMS;uid=INTRANET\sysemtmslive;pwd=test123;T rusted_Connection=no"
.Open
End With

End Sub

I would like to seek for your advise on how can I connect to the SQL server from MS Access using the domain login id and password I specified in the above-mentioned code. Can you provide me with a code to test.

Thanks and I am hoping that you could help me the soonest possible time.

Best Regards,
Matt
Oct 18 '06 #1
2 7372
MMcCarthy
14,534 Expert Mod 8TB
This should work. Make sure you have the ADO library enabled. In the VB Editor go to Tools - References and make sure that the Microsoft ADO library is clicked.

Expand|Select|Wrap|Line Numbers
  1.  
  2. Private Sub Command0_Click()
  3. Dim lobjCn As New ADODB.Connection
  4. lobjCn.Open = "Provider=sqloledb;Server=LDNPCM05421V05A,10501;Database=TMS;" & _ "uid=INTRANET\sysemtmslive;pwd=test123;Trusted_Connection=no"
  5.  
  6. End Sub
  7.  
  8.  
What do you want to do once you've made the connection. The following example will show you the kind of things you could do:

Expand|Select|Wrap|Line Numbers
  1.  
  2. Public Sub CompleteDatabaseExample() 
  3.     Dim dbMain as New ADODB.Connection' Declaring the Connection 
  4.     Dim rsCustomer as New ADODB.Recordset' Declaring the Recordset 
  5.     Dim SQL as String' Declaring a simple variable 
  6.  
  7.     dbMain.Open "Provider=Microsoft.Jet.OLEDB.4.0;" & _ ' Connecting to the Database 
  8.         "Persist Security Info=False;" & _ 
  9.         "Data Source=C:\WINDOWS\Desktop\training.mdb" 
  10.  
  11.     SQL = "SELECT * FROM Customer"' Setting up our SQL Command statement 
  12.     rsCustomer.Open SQL, dbMain, adOpenDynamic, adLockOptimistic' Opening the Recordset (see Recordset Options) 
  13.     Do While Not rsCustomer.EOF' Loop until we reach the End-Of-File marker 
  14.         MsgBox "The Customer's Name is: " & rsCustomer("Name") 
  15.         MsgBox "The Customer's City is: " & rsCustomer("City") 
  16.         rsCustomer("Country") = "United States" 
  17.         rsCustomer("Name") = rsCustomer("Name") & " Jr." 
  18.         rsCustomer.Update' Updating the Records (see also Recordset (Working With)) 
  19.         rsCustomer.MoveNext' Moving to the next record (necessary to reach the EOF) 
  20.     Loop 
  21.     rsCustomer.Close' Closing the recordset 
  22.     dbMain.Close' Closing the database connection 
  23.  
  24. End Sub
  25.  
  26.  
Oct 18 '06 #2
Hi.

I already selected the Microsoft ADO library but still fails. The login id I provided in the code is a domain account not the SQL server login id itself. I believe I cannot access the sql server using the domain login id. Do you have any idea of impersonating a sql server login id to get connected? I need to fetch the data from the sql server and insert them to the MS Access table.

Again, thanks for the prompt reply.

:)Matt


This should work. Make sure you have the ADO library enabled. In the VB Editor go to Tools - References and make sure that the Microsoft ADO library is clicked.

Expand|Select|Wrap|Line Numbers
  1.  
  2. Private Sub Command0_Click()
  3. Dim lobjCn As New ADODB.Connection
  4. lobjCn.Open = "Provider=sqloledb;Server=LDNPCM05421V05A,10501;Database=TMS;" & _ "uid=INTRANET\sysemtmslive;pwd=test123;Trusted_Connection=no"
  5.  
  6. End Sub
  7.  
  8.  
What do you want to do once you've made the connection. The following example will show you the kind of things you could do:

Expand|Select|Wrap|Line Numbers
  1.  
  2. Public Sub CompleteDatabaseExample() 
  3.     Dim dbMain as New ADODB.Connection' Declaring the Connection 
  4.     Dim rsCustomer as New ADODB.Recordset' Declaring the Recordset 
  5.     Dim SQL as String' Declaring a simple variable 
  6.  
  7.     dbMain.Open "Provider=Microsoft.Jet.OLEDB.4.0;" & _ ' Connecting to the Database 
  8.         "Persist Security Info=False;" & _ 
  9.         "Data Source=C:\WINDOWS\Desktop\training.mdb" 
  10.  
  11.     SQL = "SELECT * FROM Customer"' Setting up our SQL Command statement 
  12.     rsCustomer.Open SQL, dbMain, adOpenDynamic, adLockOptimistic' Opening the Recordset (see Recordset Options) 
  13.     Do While Not rsCustomer.EOF' Loop until we reach the End-Of-File marker 
  14.         MsgBox "The Customer's Name is: " & rsCustomer("Name") 
  15.         MsgBox "The Customer's City is: " & rsCustomer("City") 
  16.         rsCustomer("Country") = "United States" 
  17.         rsCustomer("Name") = rsCustomer("Name") & " Jr." 
  18.         rsCustomer.Update' Updating the Records (see also Recordset (Working With)) 
  19.         rsCustomer.MoveNext' Moving to the next record (necessary to reach the EOF) 
  20.     Loop 
  21.     rsCustomer.Close' Closing the recordset 
  22.     dbMain.Close' Closing the database connection 
  23.  
  24. End Sub
  25.  
  26.  
Oct 18 '06 #3

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

Similar topics

4
by: Jeremy | last post by:
In my ASP.NET web applications I would like to use "integrated security=SSPI" instead of supplying a SQL Server account credentials. From what I understand there are security policy settings...
14
by: John J. Hughes II | last post by:
I have "Computer A" which is running Win2K3 and MS SQL server. And "Computer B" which is running a service that I have created. If I change the service on "Computer B" to run as a user my program...
11
by: Patrick | last post by:
I have an ASP.NET application that connects to a SQL Server database. The SQL Server resides on a seperate development server from the IIS5.1 on Windows XP SP2 on development PCs which host the...
4
by: Matt Dockerty | last post by:
Hi, I'm trying to connect to a network share using a username / password / domain of my choosing. I've tried the WindowsIdentity.Impersonate route but can only impersonate the users on the...
2
by: josef | last post by:
This seems like a bad idea, but I'm having trouble identifying why. With an ASP.NET application I am using Windows Integrated Authentication. The aspnet_wp.exe runs as 'machine' per the...
1
by: J-T | last post by:
We are using **NTLM** as the authentication type.If I use this in my ASP.NET application : <identity impersonate="true" username="MyUser" password="123"/> <authentication mode="Windows" /> ...
2
by: Patrick F | last post by:
Hi, i have SQL Server 2005 and a database set that is called, myCompany the problem is that i cant connect from my page to it, here is from the web.config: ( i have got this connectionstring from...
1
by: avinashibs | last post by:
using socket :- how i use the socket for connecting the domain server, e,g :- i have an account on gmail emailid :- xyx@gmail.com pass:- 1354 how i will check my account is exit on that...
5
by: =?Utf-8?B?QWRyaWFuTW9ycmlz?= | last post by:
Hello! I'm trying to copy a file from another computer on the network that I do not have permission with my current logon details to access. If I open the folder using the Windows file manager...
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...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.