Hello All
I'm developing a small app in MS Excel (using VBA ofcourse) that needs to establish connection with SQL Server & run a code that is input. It turned out quite a challenge for me that I frankly never expected.
The Excel will reside on our local laptops that is in, say DOMAIN1 where we login as DOMAIN1\654321
The SQL Server instance & DB resides on DOMAIN2, where we login as DOMAIN2\LastFirstName. We have Administrative access to this instance ONLY using Windows Authentication.
From our local laptop, we use VPN connection to gain access to SQL Server systems. Which means, we're able to ping the server ip OR hostname ONLY when the VPN connection is being established.
THE PROBLEM - DSN or DSN Less connections are working only when the VBA code & SQL Server instance are on same network/domain
I've tried...
Attempt 1 - Which never worked!!
ConnectionString = "Provider=SQLOLEDB;Data Source=DBSERVER;Initial Catalog=DBNAME;Trusted_connection=Yes;Integrated Security=SSPI"
Set DBServer = New ADODB.Connection
DBServer.Open ConnectionString, "DOMAIN\LastFirstName", "Password"
DBServer.Close
Attempt 2 - Which never worked!!
ConnectionString = "Description=DSN For SQL Server" & vbCr & "SERVER=DBSERVER" & vbCr & "DATABASE=DNNAME" & vbCr & "Trusted_Connection=Yes"
DBEngine.RegisterDataBASE "SPDSNLess", "SQL Server", True, ConnectionString
DBEngine.OpenDatabase "DSN=SPDSNLess"
Attemp 3 - Again never worked!!
- Created a DSN (both ODBC & SQL Native)
- Tried changing the username & password dynamically using VBA
Attempt 4 - Testing if the connection actually works
- Installed SSMS
- Started SSMS from command prompt using "runas /noprofile /netonly /DOMAIN2\LastFirstName ssms.exe"
- It prompted for password & when supplied...VOILA!! It worked!! I was able to connect to DBSERVER\INSTANCE, which proved that it is actually possible to connect to SQL Server on other domain from local laptop
So my question - Please guide me as how the VBA code (either DSN Less or with DSN) has to be inorder to establish connectivity, but should be able to connect from our laptop logged in as DOMAIN1\654321 to SQL Server DBSERVER\INSTANCE which is on DOMAIN2\LastFirstName (accessible when we connect through VPN)
Thank you
RG
I'm developing a small app in MS Excel (using VBA ofcourse) that needs to establish connection with SQL Server & run a code that is input. It turned out quite a challenge for me that I frankly never expected.
The Excel will reside on our local laptops that is in, say DOMAIN1 where we login as DOMAIN1\654321
The SQL Server instance & DB resides on DOMAIN2, where we login as DOMAIN2\LastFirstName. We have Administrative access to this instance ONLY using Windows Authentication.
From our local laptop, we use VPN connection to gain access to SQL Server systems. Which means, we're able to ping the server ip OR hostname ONLY when the VPN connection is being established.
THE PROBLEM - DSN or DSN Less connections are working only when the VBA code & SQL Server instance are on same network/domain
I've tried...
Attempt 1 - Which never worked!!
ConnectionString = "Provider=SQLOLEDB;Data Source=DBSERVER;Initial Catalog=DBNAME;Trusted_connection=Yes;Integrated Security=SSPI"
Set DBServer = New ADODB.Connection
DBServer.Open ConnectionString, "DOMAIN\LastFirstName", "Password"
DBServer.Close
Attempt 2 - Which never worked!!
ConnectionString = "Description=DSN For SQL Server" & vbCr & "SERVER=DBSERVER" & vbCr & "DATABASE=DNNAME" & vbCr & "Trusted_Connection=Yes"
DBEngine.RegisterDataBASE "SPDSNLess", "SQL Server", True, ConnectionString
DBEngine.OpenDatabase "DSN=SPDSNLess"
Attemp 3 - Again never worked!!
- Created a DSN (both ODBC & SQL Native)
- Tried changing the username & password dynamically using VBA
Attempt 4 - Testing if the connection actually works
- Installed SSMS
- Started SSMS from command prompt using "runas /noprofile /netonly /DOMAIN2\LastFirstName ssms.exe"
- It prompted for password & when supplied...VOILA!! It worked!! I was able to connect to DBSERVER\INSTANCE, which proved that it is actually possible to connect to SQL Server on other domain from local laptop
So my question - Please guide me as how the VBA code (either DSN Less or with DSN) has to be inorder to establish connectivity, but should be able to connect from our laptop logged in as DOMAIN1\654321 to SQL Server DBSERVER\INSTANCE which is on DOMAIN2\LastFirstName (accessible when we connect through VPN)
Thank you
RG