I am trying to manually upload a number of report RDL files to SSRS using the rs.exe utility and specifying the user name and password in the command. The command executes correctly and the report is uploaded. However, the user credentials are not visible in the Data Source section of the reports properties. If I upload the same report from Report Builder, the user credentials appear correctly under the Data Source section.
This is the command I am running:
rs -i DeployReports.rss -s http://server11/ReportServer_SDM2016 -v tu=XXXX -v tp=XXXXXXX -v ReportFolder=\Development\sandbox\ssrs -v TargetFolder=/ReportTest -v ReportName=Report1
If I use the switches -u XXX and -p XXXXXX instead of the -v tu=XXXX switches, then the command returns "Could not connect to server".
I have been going around in circles for day trying to find a solution, any ideas???
Thanks
Duncan
This is the script I am running.
Public Sub Main()
try
Dim ReportDefinition As [Byte]() = Nothing
Dim warnings as Warning() = Nothing
Dim description As New [Property]
Dim properties(0) As [Property]
' Open rdl file
Dim rdlfile As FileStream = File.OpenRead(ReportFolder + "\" + ReportName + ".rdl")
console.write(ReportFolder + "\" + ReportName + ".rdl")
'read report definition
ReportDefinition = New [Byte](rdlfile.Length-1) {}
rdlfile.Read(ReportDefinition, 0, CInt(rdlfile.Length))
rdlfile.Close()
'Set Report Description
description.Name = "Description"
description.Value = "This is my demo report"
properties(0) = description
'Create Report on Report Server
warnings = rs.CreateReport(ReportName, TargetFolder, True, ReportDefinition, Properties)
'display warnings if there are any
If Not (warnings Is Nothing) Then
Dim warning As Warning
For Each warning In warnings
Console.WriteLine(warning.Message)
Next warning
Else
Console.WriteLine("Report: " + ReportName + " published successfully with no warnings")
End If
Catch e As IOException
Console.WriteLine(e.Message)
End Try
End Sub
I think I am barking up the wrong tree with the -u -p switches, as suggested.
I somehow need to set the credentials of the uploaded report with the correct user name and password. I cant find the correct way to do it so far.
What I dont want to have to do is upload each report and then add the user credentials manually.
Cheers.
Related
I am getting the User Defined Type not Defined error with the VBA code below.
I didn't write it and don't know how to fix it, but I need to use the file. It's an access database that requires users to log-in. I can't even log in (this is the error I get when I try), let alone import a file.
Can anyone help?
Public Sub RefreshPrograms(pXML As MSXML2.DOMDocument)
Dim sql As String
Dim iNode As MSXML2.IXMLDOMNode
Dim tnode As MSXML2.IXMLDOMNode
Set iNode = pXML.selectSingleNode("//ProgramUrl")
Set tnode = pXML.selectSingleNode("//" & mProgramNameTag)
If iNode Is Nothing Then
MsgBox "The file you attempted to import is not a valid program list file. You must download the program list file from the ASN RDA Information Server and then import it into the database. If you are trying to import a PoPS assessment XML file, return to the Program Selection window and click 'Import Assessment from XML'.", vbExclamation, "Invalid Program List File"
ElseIf tnode Is Nothing Then
MsgBox "The file you attempted to import is not a valid " & mName & " program list file. You must download the program list file from the ASN RDA Information Server and then import it into the database. If you are trying to import a PoPS assessment XML file, return to the Program Selection window and click 'Import Assessment from XML'.", vbExclamation, "Invalid Program List File"
Else
mURL = iNode.Text
For Each iNode In pXML.selectNodes("//" & mProgramNameTag)
sql = "INSERT INTO TempRemotePrograms (SourceID,RemoteID,Name,ACAT,Organization,PM,PEO) " & _
"Values(" & JoinStrings(True, mID, ReadLongElement(iNode, ID_COLUMN_XML_NAME), ReadStringElement(iNode, "ProgramName"), fACAT.FindByName(ReadStringElement(iNode, "ACAT")).ID, ReadStringElement(iNode, "OrganizationCode"), ReadStringElement(iNode, "PMName"), ReadStringElement(iNode, "PEOName")) & ")"
CurrentDb.Execute sql, dbFailOnError
Next
If DCount("RemoteID", "TempRemotePrograms") > 0 Then
ClearDeletedPrograms
UpdateProgramInfo
InsertNewProgramInfo
mLastUpdated = Now()
Save
End If
End If
Set iNode = Nothing
End Sub
In the VBA Editor, menu Tools -> References, activate Microsoft XML, v6.0
The missing reference generates the compile error.
If you need to edit the code, check out the msxml tag info.
I got this code and getting an error prompt. Database Login. Even I put the right password, it always says Login Failed.
Dim report As New ReportDocument
report.Load("rptPrntIss.rpt")
report.RecordSelectionFormula = "{tbl_issued.TransactionID}=" & txtIssID.Text & "AND ({tbl_transaction.Department}=" & cBoxDpt.Text & ")"
frmPrnt.CrystalReportViewer1.ReportSource = report
frmPrnt.CrystalReportViewer1.Refresh()
frmPrnt.ShowDialog()
Maybe this code is not right, because everything was perfect without this code.
use setdatabaselogon() function to prevent prompting database logon each time.
it will be like
report.SetDatabaseLogon("username", "password", "server", "dbname", false)
in some cases this will also wont work(had some situations recently for me),in that case we need to specify database login for each tables in report.
like
dim connInfo as new ConnectionInfo()
connInfo.ServerName = yourserver
connInfo.DatabaseName = "dbname"
connInfo.UserID = "username"
connInfo.Password = "password"
dim tableLogOnInfo as new TableLogOnInfo()
tableLogOnInfo.ConnectionInfo = connInfo
foreach Table as table in reportDoc.Database.Tables
table.ApplyLogOnInfo(tableLogOnInfo)
table.LogOnInfo.ConnectionInfo.ServerName = connInfo.ServerName
table.LogOnInfo.ConnectionInfo.DatabaseName = connInfo.DatabaseName
table.LogOnInfo.ConnectionInfo.UserID = connInfo.UserID
table.LogOnInfo.ConnectionInfo.Password = connInfo.Password
next
hope this helps.
I have an Access 2013 database separated into two files - data and code. In the code file, I have an autoexec routine to run the following function:
Function Reconnect()
On Error GoTo ReconnectErr
Dim db As Database, source As String, path As String
Dim dbsource As String, i As Integer, j As Integer
Set db = DBEngine.Workspaces(0).Databases(0)
For i = Len(db.Name) To 1 Step -1
If Mid(db.Name, i, 1) = Chr(92) Then
path = Mid(db.Name, 1, i)
Exit For
End If
Next
For i = 0 To db.TableDefs.Count - 1
If db.TableDefs(i).Connect <> " " Then
source = Mid(db.TableDefs(i).Connect, 11)
For j = Len(source) To 1 Step -1
If Mid(source, j, 1) = Chr(92) Then
dbsource = Mid(source, j + 1, Len(source))
source = Mid(source, 1, j)
If source <> path Then
db.TableDefs(i).Connect = ";Database=" + path + dbsource
db.TableDefs(i).RefreshLink
End If
Debug.Print dbsource, source
Exit For
End If
Next
End If
Next
GoTo ReconnectEnd
ReconnectErr:
MsgBox Err.Number & " " & Err.Description
ReconnectEnd:
End Function
The code works fine until I change the folder name (for instance, from MTDB to MTDB2) When I launch, I get the following error:
"C:\Users...\OLDPATH\MT-Data.accdb is not a valid path. Make sure that the path name is spelled correctly and that you are connected to the server on which the file resides."
Upon clicking OK, that same error occurs for each table object in the database. When the program loads, I get empty recordsets. I quit and relaunch and it works fine.
I suspect that there is a link reference somewhere before autoexec is called that carries the old path information and isn't updated at load time.
The code and data files will always be in the same folder.
Any thoughts on why I'm getting the error message when I change the name of the folder?
I figured this out - if you have directed Access to open the startup form using Options/Current Database/Display Form, it apparently gets processed first in the hierarchy. If you leave the Display Form blank and open it from the autoexec macro, it gets processed after the Reconnect() function gets called.
I am trying to create a button on my access form that allows for the user to view the corresponding page that goes with the data within the form (In this case, a part number is displayed on the form, and I want the button to open the Part Standard file to show the blueprint/diagram of said part)
I have tried using Adobe's page parameters #page=pagenum at the end of my filepath, but doing this doesn't work.
Here is the code I have (Basic, I know) but I'm trying to figure out where to go here. I have simple condensed down my filepath, for obvious reasons - Note: It's not a URL, but a file path if this matters.
Private Sub Command80_Click()
Dim loc As String 'location of file
'loc = Me.FileLoc
loc = "G:\*\FileName.pdf#page=1"
Debug.Print loc
'Debug.Print Me.FileLoc
'Debug.Print Me.FileName
Application.FollowHyperlink loc
End Sub
Is this possible to do this way? I will continue to read other users posts in hopes to find a solution, and I'll note here if I do find one.
Thanks!
Update
I've found a way to do this, just I have 1 small complication now. My database will be accessed by many users, possibly with different versions of Acrobat, or different locations. Here is my working code:
Private Sub Command2_Click()
pat1 = """C:\Program Files\Adobe\Reader 9.0\Reader\AcroRd32.exe"""
pat2 = "/A ""page=20"""
pat3 = """G:\*\FileName.pdf"""
Shell pat1 & " " & pat2 & " " & pat3, vbNormalFocus
End Sub
Now, here is my concern. This code opens AcroRd32.exe from a specific file path, if my users have this stored elsewhere or have a different version, this won't work. Does anyone have a suggestion as how to possibly get around this?
Thanks again! :)
The correct way to do this is probably to look up the location of the acrobat reader executable in the system registry. I find that's generally more trouble than it's worth, especially if I have some control over all of the places my program will be installed (within a single intranet, for example). Usually I end up using this function that I wrote:
'---------------------------------------------------------------------------------------
' Procedure : FirstValidPath
' Author : Mike
' Date : 5/23/2008
' Purpose : Returns the first valid path found in a list of potential paths.
' Usage : Useful for locating files or folders that may be in different locations
' on different users' computers.
' Notes - Directories must be passed with a trailing "\" otherwise the function
' will assume it is looking for a file with no extension.
' - Returns Null if no valid path is found.
' 5/6/11 : Accept Null parameters. If all parameters are Null, Null is returned.
'---------------------------------------------------------------------------------------
'
Function FirstValidPath(ParamArray Paths() As Variant) As Variant
Dim i As Integer
FirstValidPath = Null
If UBound(Paths) - LBound(Paths) >= 0 Then
For i = LBound(Paths) To UBound(Paths)
If Not IsNull(Paths(i)) Then
If Len(Dir(Paths(i))) > 0 Then
FirstValidPath = Paths(i)
Exit For
End If
End If
Next i
End If
End Function
The function takes a parameter array so you can pass it as many or as few paths as necessary:
PathToUse = FirstValidPath("C:\Program Files\Adobe\Reader 9.0\Reader\AcroRd32.exe", _
"C:\Program Files\Acrobat\Reader.exe", _
"C:\Program Files (x86)\Acrobat\Reader.exe", _
"C:\Program Files\Acrobat\12\Reader.exe")
pat1 = """" & PathToUse & """"
Registry keys are the better way to go, unlike file locations they have consistency between systems.
Below are three functions, two in support of one, and a macro which tests the functions.
GetARE() (Get Adobe Reader Executable) returns the proper path based on a version search in a pre-defined location passed as the argument. This removes the hassle of typing out many different key locations for each version and provides some amount of coverage should future versions be released and installed on a user's system.
I have installed previous versions of Reader to test whether or not the there is consistency in the InstallPath key location, up until quite outdated versions, there is. In fact, mwolfe02 and I both have our keys in the same location, though I am using version 11 and he, at the time of writing, was using 10. I was only able to test this on a x64 system, but you can easily modify the code below to search for both x64 and x86 keys. I expect a large corporation like Adobe to stick to their conventions, so this will likely work for quite some time without much modification even as new versions of Reader are released.
I wrote this quickly, expect inefficiency and inconsistency in naming conventions.
Truly the best approach to ensure the path is almost-always returned would be to simply run a registry search through VBA in a loop for version numbers using "*/Acrobat Reader/XX.YY/InstallPath/" and then including the executable based on a check for the appropriate candidate in the appropriate directory; however, this isn't exactly a very cost-effective solution. My tests have shown that there is quite a bit of consistency between versions as to where the Install Path can be found, and as to what the executable name may be, so I opted for something more efficient if less lasting.
RegKeyRead() and RegKeyExists() were taken from:
http://vba-corner.livejournal.com/3054.html
I have not modified their code. Take into consideration saying thanks to the author of that post, the code is not complex by any means but it did save me the hassle of writing it myself.
Function RegKeyRead(i_RegKey As String) As String
Dim myWS As Object
On Error Resume Next
'access Windows scripting
Set myWS = CreateObject("WScript.Shell")
'read key from registry
RegKeyRead = myWS.RegRead(i_RegKey)
End Function
Function RegKeyExists(i_RegKey As String) As Boolean
Dim myWS As Object
On Error GoTo ErrorHandler
'access Windows scripting
Set myWS = CreateObject("WScript.Shell")
'try to read the registry key
myWS.RegRead i_RegKey
'key was found
RegKeyExists = True
Exit Function
ErrorHandler:
'key was not found
RegKeyExists = False
End Function
Function GetARE(i_RegKey As String) As String
Dim InPath As String
Dim InKey As String
Dim Ind As Integer
Dim PriVer As String
Dim SubVer As String
Dim Exists As Boolean
Exists = False
PriVer = 1
SubVer = 0
For Ind = 1 To 1000
If SubVer > 9 Then
PriVer = PriVer + 1
SubVer = 0
End If
Exists = RegKeyExists(i_RegKey + "\" + PriVer + "." + SubVer + "\InstallPath\")
SubVer = SubVer + 1
If Exists = True Then
SubVer = SubVer - 1
InKey = i_RegKey + "\" + PriVer + "." + SubVer + "\InstallPath\"
InPath = RegKeyRead(InKey)
GetARE = InPath + "\AcroRd32.exe"
Exit For
End If
Next
End Function
Sub test()
Dim rando As String
rando = GetARIP("HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Adobe\Acrobat Reader")
MsgBox (rando)
End Sub
I remember that Acrobat reader used to include some ActiveX PDF reader object available for further use with Microsoft Office. Other companies have developed similar products, some of them (in their basic form) even available for free.
That could be a solution, couldn't it? You'd have then to check that your activeX PDF reader supports direct page access in its methods, and distribute it with your apps, or have it installed on your user's computers. It will avoid you all the overhead related to acrobat readers versions follow-up, specially when newer versions will be available on the market and you'll have to update your client interface.
Just to add to mwolfe02's answer, here is a function that tries to retrieve the executable for the file type given (it also uses the registry commands Levy referenced) :
Function GetShellFileCommand(FileType As String, Optional Command As String)
Const KEY_ROOT As String = "HKEY_CLASSES_ROOT\"
Dim sKey As String, sProgramClass As String
' All File Extensions should start with a "."
If Left(FileType, 1) <> "." Then FileType = "." & FileType
' Check if the File Extension Key exists and Read the default string value
sKey = KEY_ROOT & FileType & "\"
If RegKeyExists(sKey) Then
sProgramClass = RegKeyRead(sKey)
sKey = KEY_ROOT & sProgramClass & "\shell\"
If RegKeyExists(sKey) Then
' If no command was passed, check the "shell" default string value, for a default command
If Command = vbNullString Then Command = RegKeyRead(sKey)
' If no Default command was found, default to "Open"
If Command = vbNullString Then Command = "Open"
' Check for the command
If RegKeyExists(sKey & Command & "\command\") Then GetShellFileCommand = RegKeyRead(sKey & Command & "\command\")
End If
End If
End Function
so,
Debug.Print GetShellFileEx("PDF")
outputs:
"C:\Program Files (x86)\Adobe\Reader 11.0\Reader\AcroRd32.exe" "%1"
and you just have to replace the "%1" with the file you want to open and add any parameters you need.
Here is code the probably you can use..
Private Sub CommandButton3_Click()
Dim strFile As String
R = 0
If TextBox7 = "CL" Then
R = 2
' Path and filename of PDF file
strFile = "E:\Users\Test\Cupertino Current system.pdf"
ActiveWorkbook.FollowHyperlink strFile
End If
if R = 0 Then
MsgBox "Wrong Code"
ComboBox1 = ""
TextBox1 = Empty
'ComboBox1.SetFocus
End If
End Sub
Just need to the right path.. Hope this can help you
I have a Microsoft Access 2007 (accdb) file. I set a password on it. When I open it up now, I am prompted for a password. I enter the correct password and I can gain access to it.
However, I want to remove the password. I click "Database tools", but in the database tools, I only see "Encrypt with password", contrary to the help file (which says I should see "decrypt password.")
It appears that the Access UI thinks I have no password, so it won't give me the option to remove the password.
How can I get the password removed?
Create a new Access database
Create a new Form
Create Command button
execute below code (change code to reach your database and password)
Public Sub Command0_Click()
Dim objConn As ADODB.Connection
Dim strAlterPassword As String
On Error GoTo ChangeDBPassword_Err
' Create the SQL string to change the database password.
' Here, "It" is the old password, and I am wanting to set the password to NULL
' Replace "It" with your password
strAlterPassword = "ALTER DATABASE PASSWORD NULL [It];"
' Open the secured database.
Set objConn = New ADODB.Connection
With objConn
.Mode = adModeShareExclusive
.Provider = "Microsoft.ACE.OLEDB.12.0"
' Replace "It" with your old password
.Properties("Jet OLEDB:Database Password") = "It"
'The following specifies the location of the database of which PW I'm trying to change.
' Replace path to your database
.Open "Data Source= G:\Database\database.accdb;"
' Execute the SQL statement to change the password.
.Execute (strAlterPassword)
End With
' Clean up objects.
objConn.Close
Set objConn = Nothing
ChangeDBPassword_Err:
MsgBox Err.Number & ":" & Err.Description
End Sub
THANKS TO ERIC MATTHEW VAJENTIC
Did you open the database in "exclusive mode"?
File | Open | select database file |
Triangle Next to the "Open" command
button | Open Exclusive