List SQL Express 2005 instances using VB6 code - sql-server-2005

How to list all the instances of SQL Server 2005 Express Edition using vb6 application?

This will list all SQL Server instances using SQL-DMO. You will need to filter for Express instances.
Function listServers(vControl As Object)
Dim oApp As SQLDMO.Application
Dim oNames As SQLDMO.NameList
Set oApp = New SQLDMO.Application
Set oNames = oApp.ListAvailableSQLServers()
For Each oName In oNames
vControl.AddItem oName
Next
End Function
From here.
This SO question says that it won't find Express instances; need to use SQLBrowseConnect.

This sample is using SQLBrowseConnect API.

Related

MS-Access in Sharepoint - what data available?

For better or worse we are launching an Access db from Sharepoint. Note that this db is not PUBLISHED to SP, people just double-click the link and open the db on their desktops.
So now we need to begin imposing the equivalent of some roles-based edit restrictions. I know there is a VBA CurrentWebUser function and a CurrentWebUserGroups which provides some basic data about who's accessing an Office file from Sharepoint. However my reading and limited experimenting with this stuff leads me to suspect that, for Access at least, these will only work with published dbs, and not ones that are just being launched and run locally, like we're doing.
Is there anything I can get from SP in a case like this? Web user and user group would be useful, so would whichever site/page the link is being clicked on. Is any of this available?
Thanks.
rabbit
Well, not in any simple way.
As you've already determined, Application.CurrentWebUser just returns Null.
However, there are several ways to query the user information from SharePoint.
The recommended way (also by me) if you're going to work with SharePoint extensively, is to use the CSOM api, which requires a .Net language, so you'll have to create a COM module, authenticate it separately, and that's all a lot of work.
However, if you're only using simple GET requests, you can also use the REST API and re-use the authentication MS Access uses itself (since MS Access uses MSXML2 to submit web requests to SharePoint, we can create our own MSXML2.XMLHTTP object and it will re-use the cookies Access uses).
The following code uses the JSONInterpreter object I've shared here on GitHub. You could convert it to use XML and MSXML if you don't want that dependency, though.
To execute a request, I use the following code, that assumes the Access application is authenticated, but if it isn't, it connects to the SharePoint site using ADO.
(For this code, MySiteName is a global variable containing the URL of your SharePoint site, without a trailing slash)
Public Function SPRestGetJSON(Site As String, Request As String) As String
Dim tries As Long
Dim Success As Boolean
Do
'Try to execute request
tries = tries + 1
Dim xmlHttpReq As Object 'MSXML2.XMLHTTP60
Set xmlHttpReq = CreateObject("Msxml2.XMLHTTP.6.0") 'New MSXML2.XMLHTTP60
xmlHttpReq.Open "GET", Site & Request, False
xmlHttpReq.setRequestHeader "Content-Type", "application/json"
xmlHttpReq.setRequestHeader "Accept", "application/json;odata=nometadata"
xmlHttpReq.send
Dim root As JSONInterpreter
Set root = New JSONInterpreter
root.JSON = xmlHttpReq.responseText
If Not root.Exists("odata.error") Then
Success = True
End If
If Not Success And tries = 1 Then
'Connect to SharePoint using WSS + ADO to create auth cookies inside MSXML
Dim conn As Object 'ADODB.Connection
Set conn = CreateObject("ADODB.Connection") 'New ADODB.Connection
conn.Open "Provider=Microsoft.ACE.OLEDB.12.0;WSS;DATABASE=" & Site
On Error Resume Next
conn.Execute "SELECT 1 From SomeTable" 'Execute to non-existent table but connect to sharepoint
On Error GoTo 0
conn.Close
End If
Loop While tries < 2 And Success = False
SPRestGetJSON = xmlHttpReq.responseText
End Function
Then, we can use that in a simple function:
Public Function GetSPUsername() As String
Dim jsi As New JSONInterpreter
jsi.JSON = SPRestGetJSON(MySiteName, "/_api/Web/CurrentUser")
GetSPUsername = jsi.item("LoginName").VBAVariant
End Function
Getting groups is also available. This code returns an array of dictionary objects, you can view the available keys in the locals window:
Public Function GetSPGroups() As Variant 'Array of dictionaries
Dim jsi As New JSONInterpreter
jsi.JSON = SPRestGetJSON(SiteName, "/_api/Web/CurrentUser/Groups")
GetSPGroups = jsi.item("value").VBAVariant
End Function
Then, to get the title of the first group the current user is a member of in the immediate window, we can use:
?GetSPGroups(0)!Title

Unable to delete inherited file permissions in VB6 on Windows 2012 R2

I have a legacy VB6 COM application that I’ve recently had to migrate from a Windows 2008 R2 to a Windows 2012 R2 environment. The application works well apart from a section that strips the inherited permissions of certain (confidential) folders created on remote machines. The same code (below) works as expected on Windows 2008, however on Windows 2012 (using the same AD service account), will only delete permissions explicitly created on the folder in question. Does anyone know what has changed or what I’m doing wrong? I have noticed that the version of activeds.dll (C:\Windows\SysWOW64) has increased from 6.1.7601.17514 to 6.3.9600.17415.
Public Sub RemoveInheritedPermissions(ByVal sNTFSPath As String)
Dim sec As New ADsSecurityUtility
Dim sd As SecurityDescriptor
Dim ace As New AccessControlEntry
Dim dacl As Object
Set sd = sec.GetSecurityDescriptor(sNTFSPath, ADS_PATH_FILE, ADS_SD_FORMAT_IID)
Set dacl = sd.DiscretionaryAcl
For Each ace In dacl
dacl.RemoveAce ace
Next
sd.DiscretionaryAcl = dacl
sec.SetSecurityDescriptor sNTFSPath, ADS_PATH_FILE, sd, ADS_SD_FORMAT_IID
Set sec = Nothing
Set sd = Nothing
Set dacl = Nothing
Set ace = Nothing
End Sub
Thanks in advance.

Multiple databases in MS Access VBA?

This Microsoft KB article details how to run a query on another database than the current one used by the Access project. However it only states how to connect to DBase, Foxpro, Paradox, BTrieve and ODBC.
I want to be able to do something like this:
UPDATE MSSQLDatabase.Table
SET MSSQLDatabase.Table.Column = AccessDatabase.Table.Column
WHERE MSSQLDatabase.Table.Column = AccessDatabase.Table.ID
INSERT INTO AccessDatabase.Table
VALUES (AccessDatabase.Table.ID)
Can you give me any pointers of where to begin? The database I want to connect to is a SQL Server 2008 Provider Native connection. I'm using Access 2007.
To do this in VBA would be perfect.
By far the easiest way to work with SQL Server in MS Access is to use linked tables. However, you can also run pass-through queries and refer to a connection in-line:
SELECT * FROM [ODBC;FILEDSN=Z:\Docs\Test.dsn;].table_1
Or
SELECT * FROM
[ODBC;DRIVER=SQL Server;SERVER=srvr;Trusted_Connection=Yes;DATABASE=Test;].table_1
Or
SELECT * FROM [ODBC;Driver={SQL Server Native Client 11.0};Server=svr;Database=test;Trusted_Connection=yes;].table_1
see also http://www.connectionstrings.com/sql-server-2008
This solution allows to catch errors:
Private Sub Command10_Click()
On Error GoTo Err1:
Dim cn As ADODB.Connection
Set cn = New ADODB.Connection
With cn
.Provider = "SQL Native Client"
.ConnectionString = "Server=myserver\myinstance;Database=mydb;Uid=myuser;Pwd=mypass;]"
.Open
End With
MsgBox "Connection successful!"
cn.Close
Exit Sub
Err1:
MsgBox Err.DESCRIPTION
End Sub
The only thing to note, is that within the Visual Basic Editor, you must first go to Tools > References, and check Microsoft ActiveX Data Objects 2.x Library.

How do I connect to Oracle SQL using VBA?

I'm a newbie with vba, and would appreciate help with connecting to Oracle SQL using VBA.
I have such code for MS Server, and need to modify it somehow (or create a new one) so it works with Oracle SQL.
Here's the code:
Public Const sConnect As String = "xxx; Initial Catalog=xxx; User ID=xxx;Password=xxx;"
Sub GetData1()
Sheets(1).Range("a1:ao20000").ClearContents
Dim rsConnection As ADODB.Connection
Dim rsRecordset As ADODB.Recordset
Dim sQuerry As String
sQuerry = "select * from xxx"
Set rsConnection = New ADODB.Connection
Set rsRecordset = New ADODB.Recordset
rsConnection.ConnectionString = sConnect
rsConnection.Open
Set rsRecordset = rsConnection.Execute(sQuerry)
Worksheets(1).Range("A2").CopyFromRecordset rsRecordset
rsConnection.Close
Set rsConnection = Nothing
Set rsRecordset = Nothing
End Sub
My questions are:
Do i need to install anything else than Oracle Developer? If so, what?
How to change the code to make it work?
Thanks a lot in advance!!
Regards,
Maciej
You need to install Oracle client software on your computer. The smallest setup is to use Oracle instant client, see http://www.oracle.com/technetwork/database/features/instant-client/index-097480.html.
The only thing you need to change in your program is the connection string

How do I connect an SQL database to Lotus Domino Designer?

I am creating a Lotus Notes application which has to have dynamic combo boxes. The choices for the combo boxes need to be retrieved by selecting from a SQL database.
I am new to Lotus Notes / Domino, I would love to know how to connect my SQL database for use in the domino designer. Thanks.
Edit: this is the client, not the web
Sub Initialize
On Error GoTo e
Dim pw As String,user As String,odbc As String
Dim i As Integer
Dim conn As ODBCConnection,query As ODBCQuery,rs As ODBCResultSet
Dim db As NotesDatabase
Dim session As NotesSession
Dim view As NotesView
Dim doc As NotesDocument
Dim newDoc As NotesDocument
Set session = New NotesSession
Set db = session.CurrentDatabase
Set view = db.GetView("Reports")
Set doc = view.GetFirstDocument
Set conn = New ODBCConnection
Set query = New ODBCQuery
Set rs = New ODBCResultSet
Set query.Connection = conn
Set rs.Query = query
odbc = "server"
user = "user"
pw = "pass"
Call conn.ConnectTo( odbc , user , pw )
i = 0
query.SQL = "SELECT * FROM table"
rs.Execute
rs.FirstRow
Do While Not rs.IsEndOfData
i = i + 1
rs.NextRow
Loop
conn.Disconnect
Exit Sub
e :
MessageBox "Error " & Err & " line " & Erl & ": " & _
Error
Exit Sub
End Sub
The questions is tagged Lotusscript so I assume that this is Lotusscript related (and not XPages related).
Have a look at the ODBCConnection, ODBCQuery, and ODBCResultSet Lotusscript classes in the Domino Designer Help database.
If you're not able to use any XPages components, you could try the ODBC variant of #DBLookup in the 'Use formula for choices' part of your combobox.
The code you have added to the question is going to cause an infinite loop due to the while/wend
Depending on how often the choices for the dropdown boxes change you could also create a scheduled agent that connections to the SQL server. I do this a lot for some of my own internal applications as it cuts down on unnecessary traffic to the SQL server if the values being returned are always the same.
Your scheduled agent would need to use the LSXLC extensions by adding UseLSX "*lsxlc" to the options section of the Lotusscript agent.
The LSXLC has a LOT of options which would be beyond the scope of this question so I would recommend looking at the Domino Designer Help files and searching for lsxlc. There are lots of examples in the help files.
Have a look at extlib on OpenNTF. It has an XPages component that allows you to connect to make SQL calls.
http://extlib.openntf.org
if you are using an xpages application, you can use a managed bean or static java method to get the data you want and bind it to the select values of the of combobox control.