I am trying to open an access report through .net. I can open it in normal mode using Access.AcView.acViewNormal, but it's not what I want to do because that prompts the user to save the first and then it can be viewed. I want the report to pop up and it seems .acViewPreview or .acViewReport is what i should use, but it's not popping up.
It does open up a process and seems to be opening, but i can't see the report. Perhaps it's closing really fast. The following is the code I have currently
private void buttonResults_Click(object sender, EventArgs e)
{
Microsoft.Office.Interop.Access.Application oAccess = new Microsoft.Office.Interop.Access.Application();
oAccess.OpenCurrentDatabase("D:\\path.mdb",true);
try
{
oAccess.DoCmd.OpenReport("rptChartData", Microsoft.Office.Interop.Access.AcView.acViewPreview);
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
What am i doing wrong?? Thanks in advance...
I don't know Dot Net. I put this code in an Excel module and it created an Access instance and displayed my report. The key seemed to be oAccess.Visible = True Without setting Visible = True, Access opened (and remained open) with the report but was just not visible.
Dim strDbFullPath As String
Dim oAccess As Access.Application
strDbFullPath = "C:\Access\webforums\whiteboard2003.mdb"
Set oAccess = New Access.Application
oAccess.Visible = True
oAccess.OpenCurrentDatabase strDbFullPath, True
oAccess.DoCmd.OpenReport "rptFoo", acViewPreview
So I think this may not be a Dot Net issue, but standard behavior for an Access application instance.
Related
We have a number of SSRS sites serving reports to various locations. Each of these servers all have custom connections in each and every report (don't ask why, that's a tale too torrid to tell). Our goal is to replace all of these custom data sources with a single shared data source for all reports on each server.
To that end, I have created a C# program that will find each report on each server and point the current custom data sources to a currently existing shared data source. This executes and seems to work fine.
My next goal is to use C# to create the shared data source on each server where none currently exists.
My current dilemma arises here:
private static void CreateSharedDataSource(string user, string password, string connection)
{
DataSourceDefinition source = new DataSourceDefinition();
source.CredentialRetrieval = CredentialRetrievalEnum.Store;
source.ConnectString = connection;
source.Enabled = true;
source.EnabledSpecified = true;
source.Extension = "SQL";
source.ImpersonateUser = false;
source.ImpersonateUserSpecified = false;
source.Prompt = "Enter a user name and password to access the data source:";
source.UserName = user;
source.Password = password;
source.WindowsCredentials = true;
source.OriginalConnectStringExpressionBased = true;
source.UseOriginalConnectString = true;
try
{
service.CreateDataSource("DbDataSource", "/DsFolder", false, source, null);
Console.WriteLine("Data source created successfully");
}
catch (Exception e)
{
Console.WriteLine(e.Message);
}
}
The data source is created correctly and the user name and password are updated correctly. The problem is that, when I look at the newly created data source on the server, the Connect string property is empty and, yes, the correct value is being passed to it in the method above. If I plug that value into the shared source on the server and test the connection, it works fine, but I cannot get the C# program to update that value itself.
So, is there something subtle I'm missing? Am I misinterpreting a setting up there? Did I set a value wrong?
Clues appreciated.
I've never tried anything like this but a quick bit of research uncovered this which may be helpful.
https://learn.microsoft.com/en-us/dotnet/api/reportservice2010.datasourcedefinition.originalconnectstringexpressionbased?view=sqlserver-2016
It states
"Expression-based connection strings are not supported in shared data
sources."
Assuming the conneciton string is just a plain text string then I would guess that you could set this to false. This may help preserve the string you pass in.
Alright, found my answer. I had a pre-existing data source that was working so, instead of creating it from scratch, I copied that and only changed the name. That created a data source where the Connect string did persist. Comparing the settings in that with what I was setting revealed:
source.UseOriginalConnectString = false;
whereas, my code was:
source.UseOriginalConnectString = true;
Looking that up in docs and it tells me "If true, the value of the ConnectString property is ignored."
Hmmm... that's intuitive. That's not what that sounds like at all. :)
I want to browse for a folder in a LINQPad script so I tried using FolderBrowserDialog. It didn't work.
Here is a snippet showing what I'm doing?
string path = "";
var browser = new FolderBrowserDialog { ShowNewFolderButton = false };
if (browser.ShowDialog() == DialogResult.OK)
{
path = browser.SelectedPath;
}
This runs and hangs on the line with ShowDialog() with the yellow execution pointer against that line, but the folder browser dialog isn't visible.
I know that there is an overload for ShowDialog() that takes an IWin32Window owner argument and thought that might be the solution, but haven't yet figured out how to get an IWin32Window for the main LINQPad window. I hoped the Util class might provide a way but unless I'm missing it, it doesn't seem to.
Anyone have advice on getting around this problem?
Not solution, but an alternative, the FilePicker controle (part of new LinqPad Input Controls).
you can write:
new FilePicker().Dump().TextInput += (x, e) => ((FilePicker)x).Text.Dump();
or:
var picker = new FilePicker();
picker.TextInput += (x, e) => {
var fileName = picker.Text;
//action with the file...
};
full example:
void Main()
{
new FilePicker().Dump().TextInput += (x, e) => procces(((FilePicker)x).Text);
}
void procces(string file)
{
file.Dump("chosen file...");
//...
}
Setting the Run each query in its own process option to true is the cause of the problem. Setting that option back to the default false allows the code described above to run as expected.
However, making this change disables the built-in debugging. Furthermore the behaviour is still slightly problematic.
On first running the script the dialog is displayed and the script runs to completion after Ok or Cancel is selected. However, on running the script a second time it hangs as described in the question. After cancelling the execution and running it again the dialog displays but on the time after that it hangs again, and so on.
It was pointed out that setting the Always use fresh application domains option may resolve this and it does, allowing the dialog to display on every execution of the script.
I just came across this problem with LINQPad 5. I needed a folder picker similar to the file picker. Your solution worked without me having to modify LINQPad5 settings. The problem was the dialog was staying in the background. So here's how I got your snippet to work with that dialog in focus. Instead of using the FolderBrowseDialog.ShowDialog() I used the overload that passes in a windows form. I created a new form with description and window position then passed that to ShowDialog. That allowed me to set the description and window positioning.
string path = "";
using ( var browser = new System.Windows.Forms.FolderBrowserDialog { ShowNewFolderButton = false })
{
browser.Description = "Select Folder For Foo Processing";
var form = new System.Windows.Forms.Form(){TopMost = true, TopLevel = true};
var result = browser.ShowDialog(form);
if (result == System.Windows.Forms.DialogResult.OK)
{
path = browser.SelectedPath;
}
}
path.Dump();
I tried to initialize the form in ShowDialog with the settings, but had problems so I opted to declare it before show dialog. Hope this helps anyone with this problem.
I'm loading a report into my ReportViewer 10.0 along these lines:
MyReportViewer.ServerReport.ReportPath = "/My.Report.Folder/DoesNotExist";
// The following call throws a ReportServerException ("...rsItemNotFound...")
var requestedParameters = MyReportViewer.ServerReport.GetParameters();
var filledParameters = GetFilledParameters(requestedParameters);
MyReportViewer.ServerReport.SetParameters(requestedParameters);
MyReportViewer.ServerReport.Refresh();
This works fine, except when the report does not exist. In that case the GetParameters() call will fail with a ReportServerException and a message along these lines:
The item '/My.Report.Folder/DoesNotExist' cannot be found. (rsItemNotFound)
Of course I could use a try...catch block here to trap this situation, but I'd rather explicitly check if a report exists. Is there a way to do this using the ReportViewer component? Or do I need to hook into the SSRS web services?
I've gone through MyReportViewer.ServerReport's methods and properties but found nothing that seems of use. I've also checked this related question, but it's not really in the context of the ReportViewer control.
I'm open to other answers, but until then, here's my current workaround:
try
{
var requestedParameters = MyReportViewer.ServerReport.GetParameters();
var filledParameters = GetFilledParameters(requestedParameters);
MyReportViewer.ServerReport.SetParameters(requestedParameters);
MyReportViewer.ServerReport.Refresh();
}
catch (ReportServerException exception)
{
if (!exception.Message.Contains("rsItemNotFound"))
{
throw;
}
// Else... ReportViewer will show "rsItemNotFound" error.
// Or you can do something fancy in your app here, I suppose :-)
}
In fact, I have a C# application that is runned.
When it's launched, it runs an excel instance and save it to a variable :
excelApp = new Excel.Application();
Then I cycle through each of the excel's addins to find my own created added :
private void getAddin()
{
const string addinName = "myAddInName";
foreach (Office.COMAddIn addin in excelApp.COMAddIns)
if (addin.Description.ToUpper().Contains(addinName.ToUpper()))
{
myAddin = addin;
return;
}
}
The problem is that, it may happens that my plugin is in the deactivated elements list. (Due to some crash)
Then I must go to (on excel's frame) :
File >Options >AddIns >Manage >Deactivated elements >Achieve >"myAddin" >Activate
to get my addin working again (after excel's restart)...
I tried using an addin's property to reactivate it but may app crashes again in that case.
myAddin.Connect = loadAddin;
Someone has an idea on how to resolve it / auto-reactivate a disabled plugin using C# ?
This should help
http://msdn.microsoft.com/en-us/library/aa662931(v=office.11).aspx
I believe you need to do
if(!myAddin.Connect)
{
myAddin.Connect =true;
}
C# VS 2005.
I have developed an application that run perfectly on my development machine when I install it. However, it doesn't run on any of the clients machines.
I have tested with VMWare with a fresh install of windows, and still the application doesn't run.
I have added logging to try and determine where the application is failing. My previous versions worked, and after a week of development I gave to the client and then experienced this problem.
I have entered logging at the start and end of the constructor and form_load event. The constructor runs ok. However, at the end of the constructor it doesn't run in the form_load event as I have a log statement that should print out.
When the application runs it displays for a few seconds in task manager then fails to load.
I think this could be a very difficult problem to solve. So if anyone has experienced this before or could point me in the right direction to solve this problem.
The code in the form load event.
private void CATDialer_Load(object sender, EventArgs e)
{
my_logger.Info("Start of form load event"); // Doesn't display this.
.
.
}
===== Edit static main ====
[STAThread]
static void Main()
{
Application.SetCompatibleTextRenderingDefault(false);
// Get the language and set this cultureUI in the statusdisplay that will
// change the language for the whole program.
string language = CATWinSIP.Properties.Settings.Default.Language;
if (language == "th-TH")
{
StatusDisplay.StatusDisplay status_display = new StatusDisplay.StatusDisplay(true);
}
else if(language == "en-GB")
{
StatusDisplay.StatusDisplay status_display = new StatusDisplay.StatusDisplay(false);
}
try
{
Application.Run(new CATDialer());
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
}
=== Constructor ===
public CATDialer()
{
//Set the language for all the controls on the form.
//Has to be done before all components are initialized.
//If not Thai language then must be using English.
if (Settings.Default.Language == "th-TH")
{
Thread.CurrentThread.CurrentUICulture = new CultureInfo("th-TH");
}
else
{
Thread.CurrentThread.CurrentUICulture = new CultureInfo("en-GB");
}
InitializeComponent();
this.statusDisplay1.BalanceStatus = CATWinSIP_MsgStrings.BalanceStatus;
this.statusDisplay1.RedialHistory = CATWinSIP_MsgStrings.RedialHistory;
this.statusDisplay1.LoginStatus = CATWinSIP_MsgStrings.LoginSuccessful;
// Enable logging
XmlConfigurator.Configure();
logger.Info("CATDialer Constructor(): XmlConfigurator.Configure() Loaded [ OK ]");
// MessageBox.Show("Balance Status: " + this.statusDisplay1.BalanceStatus);
//Short cut menu.
this.SetupShortCutMenu();
this.fill_properties();
logger.Debug("CATDialer Constructor(): Fill properties loaded [ OK ]");
}
--
Hello,
Thanks for all the advice.
I have problem with one of my class libraries I created that used a crypto stream.
I found the answer when I added this to my program.cs
The message box displayed the information for the failed assembly.
Thanks,
try
{
Application.Run(new CATDialer());
}
catch (Exception ex)
{
MessageBox.Show(ex.ToString());
}
Have you checked on a different development machine? Are your systems running same version of the .net framework? Is the .net framework installed correctly on the remote system? Have you tested your application in a different environment?
edit: have you tried spamming your log? Wrap the entire thing in a try catch and see what you can capture. Sometimes I found using the messagebox useful for this kind of logging (MessageBox.Show())
You probably need to post a bit more detail about the type of exception that is being thrown to get the most help.
If all the obvious checks such as having the correct framework version pass, the next thing to fail can often be a missing assembly.
If this is the case you may want to troubleshoot assembly loading in your app.
The MS Assembly Binding Log Viewer (fuslogvw) is a valuable piece of kit for this task.
In this sort of scenario I frequently find .NET assembly binding log viewer (Fusion) very useful in finding out what is going on. With fusion you can see which assemblies are being loaded and where they are being loaded from. More importantly for you, it is possible to enable it so that fusion also displays the assemblies that fail to load and where .NET tried to load them from.
Check out the MSDN article on fusion if you think this might help.