473,787 Members | 2,881 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Connecting to SQL Server using domain account

2 New Member
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.Connectio n

With lobjCn
.ConnectionStri ng = "Provider=sqlol edb;Server=LDNP CM05421V05A,105 01;Database=TMS ;uid=INTRANET\s ysemtmslive;pwd =test123;Truste d_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 7441
MMcCarthy
14,534 Recognized Expert Moderator MVP
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
mattheus0525
2 New Member
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
2017
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 that need to be setup on the web server to allow for me to do this, but I'm not 100% sure what they are. I think I have to allow a remote token (from remote computers) and Kerberos, and in IIS use Integrated Windows Authentication (with basic and...
14
3401
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 is able to connect to the SQL server on "Computer A" correctly. But if I set the service on "Computer B" to run as a local system then I get an error connecting to the SQL on "Computer A" --- "NT AUTHORITY\ANONYMOUS LOGON". I understand why I...
11
2426
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 ASP.NET application. I would like to use Integrated Windows Authentication like Integrated Security=SSPI;Persist Security Info=False;Initial Catalog=DBName;Data Source=DevServer1 My problems!
4
2701
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 local machine / domain using this method. I could go about creating actual mapped drives but I'd much rather connect temporarily to a UNC share without affecting the system configuration.
2
1747
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 processModel element in machine.config. By creating a domain\machine$ user in the database, I can successfully connect to the database. So in my case the domain is flintstone and the web server is fred. By adding the flintstone\fred$ user to the database,...
1
1498
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" /> and MyUser is the local account of the box which hosts my web application ,then can I connect to a remote sql server instance which has exactly the same user name and password defined as ***Sql server authentication* using the connection string...
2
4127
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 my sqldataobject on my page) <add name="ConStr" connectionString="Data Source=localhost;Initial Catalog=myCompany;Integrated Security=True" providerName="System.Data.SqlClient" /> the strange part is that its trying to connect to a SQL express...
1
1088
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 particular domain ......
5
17765
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 with the path "\\ 192.168.2.2\temp" (where temp is a shared directory on server \\192.168.2.2), windows prompts for a User Name and password of a user who has permission on that computer to access that directory. If I enter valid details, the...
0
9497
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10363
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10110
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8993
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7517
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5398
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5534
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3670
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2894
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.