SQL Clone
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


Azure SQL database & VBA


Azure SQL database & VBA

Author
Message
Davor Geci
Davor Geci
SSC Veteran
SSC Veteran (265 reputation)SSC Veteran (265 reputation)SSC Veteran (265 reputation)SSC Veteran (265 reputation)SSC Veteran (265 reputation)SSC Veteran (265 reputation)SSC Veteran (265 reputation)SSC Veteran (265 reputation)

Group: General Forum Members
Points: 265 Visits: 163
Hello guys/girls,

what will be the best way (and secure) to create a connection from Excel VBA (ADODB) to Azure SQL database?
The users will use this workbook from their desktop machines so there a static IP is not a solution.
Is this secure and what else do I need to setup?

Sub GetDataFromADO()  
'Declare variables'
Set objMyConn = New ADODB.Connection
Set objMyRecordset = New ADODB.Recordset
Dim strSQL As String

'Open Connection'
objMyConn
.ConnectionString = "Provider=SQLOLEDB;Data Source=myAzureServer;Initial Catalog=MyDatabase;User ID=abc;Password=abc;"
objMyConn
.Open
'Set and Excecute SQL Command'
strSQL
= "select * from myTable"

'Open Recordset'
Set objMyRecordset.ActiveConnection = objMyConn
objMyRecordset
.Open strSQL

'Copy Data to Excel'
ActiveSheet.Range("A1").CopyFromRecordset (objMyRecordset)

End Sub


Grant Fritchey
Grant Fritchey
SSC Guru
SSC Guru (350K reputation)SSC Guru (350K reputation)SSC Guru (350K reputation)SSC Guru (350K reputation)SSC Guru (350K reputation)SSC Guru (350K reputation)SSC Guru (350K reputation)SSC Guru (350K reputation)

Group: General Forum Members
Points: 350952 Visits: 34261
Connecting from ADO in Powershell should be the same as VBA. I use the full server name provided: xxx.database.windows.net. That ought to work for you. You will need to make sure you allow for the fact that the firewall will block individual IP addresses, so if you have a range of those at work, add it to the firewall now.

----------------------------------------------------
The credit belongs to the man who is actually in the arena, whose face is marred by dust and sweat and blood...
Theodore Roosevelt

The Scary DBA
Author of: SQL Server 2017 Query Performance Tuning, 5th Edition and SQL Server Execution Plans, 3rd Edition
Product Evangelist for Red Gate Software
Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum








































































































































































SQLServerCentral


Search