Keep getting an error when using OledbConnection - oledbconnection

I can't seem to set up a connection when I attempt to open up an excel 2010 spreadsheet (xlsx file). I don't know what I am doing wrong. I appear to be following the tutorials to a T.
Here is the code I am trying...
static string fileName = "C:\\Code\\UPMC\\ISD\\EADIS\\UPMC.ISD.EADIS.ACO.ACOBackLoad\\App_Data\\Example ACO Epic Data File.xlsx";
try
{
//Workbook workBook = _excelApp.Workbooks.Open(excelFileName, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing);
//Worksheet wkSheet = (Worksheet)_excelApp.Worksheets[1];
//OLEObject oleObject = wkSheet.OLEObjects(Type.Missing);
using (OleDbConnection connection = new OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + fileName + ";Extended Properties=\"Excel 12.0;HDR=No;IMEX=1\""))
{
connection.Open();
}
These are my references.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Office.Interop.Excel;
using System.IO;
using System.Data;
using System.Data.OleDb;
This would be the exception.
The type initializer for 'System.Transactions.Diagnostics.DiagnosticTrace' threw an exception.
Message
Unrecognized configuration section authentication.
I get the impression I need to set up an app.config. Guess I need to find some better tutorials.

I have same problem today after added the <appSettings>
When i remove them, it works.
<appSettings> added on incorrect position will cause this error.

Related

RestSharp package update causing RestRequest problem with Method.POST

I need to update RestSharp to newest version in one project and once the newest version is installed and referenced, an existing RestRequest call causes error.
Uri uri = new Uri(url);
var client = new RestClient(uri.Scheme + "://" + uri.DnsSafeHost);
client.Authenticator = new HttpBasicAuthenticator(username, password);
var RSrequest = new RestRequest(uri.AbsolutePath, Method.POST);
What Visual Studio complains about is "Method.POST" instead of "Method.Post". Once updated to "Method.Post", project builds fine but the RestRequest call does not seem work as intended. When I look into RestRequest definition with RestSharp updated to newest version, it looks different than the old version, as it defaults to Method.Get:
public RestRequest(string? resource, Method method = Method.Get)
How can this be fixed? Obviously, I do not have much RestSharp knowledge, neighter I am the author of the code I am about to update.

Cannot use HTTP Response

I am using NPOI to save files to an .xls format.
I would like to save an empty file for now that a user has a dialog box and is prompted to save it locally.
The problem I have is I cannot set the Response fields, because
The name 'Response' does not exist in the current context.
This is the class I want to use:
https://learn.microsoft.com/en-us/dotnet/api/system.web.httpresponse?view=netframework-4.8
//Load all documents sorted by DocNumber and export them
var documents = await _ctx.Db.Documents
.AsNoTracking()
.OrderByDescending(d => d.Number)
.ToListAsync();
var workbook = new HSSFWorkbook();
var sheet = workbook.CreateSheet("Invoicing_Docs");
using (var exportData = new MemoryStream())
{
workbook.Write(exportData);
string saveAsFileName = string.Format("Invoicing_Docs-{0:d}.xls", DateTime.UtcNow).Replace("/", "-");
Response.ContentType = "application/vnd.ms-excel";
Response.AddHeader("Content-Disposition", string.Format("attachment;filename={0}", saveAsFileName));
Response.Clear();
Response.BinaryWrite(exportData.GetBuffer());
Response.End();
}
I have installed System.Web in the project.
When I ctrl + . on Response I have 3 choices:
Install package "IdentityMode",
Install package "Selenium.WebDriver"
Install package "Swashbuckle.AspNetCore.Swagger"
Also this is the article, I am following:
https://steemit.com/utopian-io/#haig/how-to-create-excel-spreadsheets-using-npoi
I don't need any of those. What am I doing wrong?
I found out what I need to do.
I was not using the controller I was writing a service that is called in the controller.
All I had to do is inject Response in the Method of the service.

How to extract members of a group in Jenkins using Groovy?

I am using Active directory plugin and in a need of listing the members of a active directory group in Jenkins itself using groovy. I have tried below code and it always returns null.
import jenkins.model.*
import hudson.security.*
import hudson.plugins.active_directory.*
def instance = Jenkins.getInstance()
String domain = 'my.domai.com'
String site = 'ldap.com:3268'
String server = 'ldap.com:3268'
String bindName = 'user'
String bindPassword = 'passwd'
adrealm = new ActiveDirectorySecurityRealm(domain, site, bindName, bindPassword, server)
adrealm.loadGroupByGroupname("my_team").getMembers()

'System.Web.HttpContext' does not contain a definition for 'GetOwinContext'

I have the following error :'System.Web.HttpContext' does not contain a definition for 'GetOwinContext'
whenever I debug my project. this error is in the web API page, although it doesn't show an error in the default AccounController.cs and the nuget package is installed.what is missing?
using IdentitySample.Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Web.Http;
using Microsoft.AspNet.Identity;
using Microsoft.AspNet.Identity.Owin;
using Microsoft.Owin.Security;
using System.Web;
using System.Threading.Tasks;
using task.Models;
using System.Globalization;
public ApplicationUserManager UserManager
{
get
{
return _userManager ?? HttpContext.GetOwinContext().GetUserManager<ApplicationUserManager>();
}
private set
{
_userManager = value;
}
}
ok I found the solution since I already installed the nuget package all I have to do is the following:
return _userManager ?? HttpContext.**current**.GetOwinContext().GetUserManager<ApplicationUserManager>();

how to configure an authorized service object using Google OAuth 2.0

On the following link there is code which should access the Google Calendar api using OAuth 2.0. Unfortunately it uses the Draft 10 Client Library which is apparently deprecated.
https://developers.google.com/google-apps/calendar/instantiate
The latest Client Library is google-api-java-client-1.12.0-beta. From what I can make out things have changed a lot since the Draft 10 Client Library and I can't work out how to rewrite this code for the current Client Library.
The deprecated code is shown below.
import com.google.api.client.auth.oauth2.draft10.AccessTokenResponse;
import com.google.api.client.googleapis.auth.oauth2.draft10.GoogleAccessProtectedResource;
import com.google.api.client.googleapis.auth.oauth2.draft10.GoogleAccessTokenRequest.GoogleAuthorizationCodeGrant;
import com.google.api.client.googleapis.auth.oauth2.draft10.GoogleAuthorizationRequestUrl;
import com.google.api.client.http.HttpTransport;
import com.google.api.client.http.javanet.NetHttpTransport;
import com.google.api.client.json.jackson.JacksonFactory;
import com.google.api.services.calendar.Calendar;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
...
public void setUp() throws IOException {
HttpTransport httpTransport = new NetHttpTransport();
JacksonFactory jsonFactory = new JacksonFactory();
// The clientId and clientSecret are copied from the API Access tab on
// the Google APIs Console
String clientId = "YOUR_CLIENT_ID";
String clientSecret = "YOUR_CLIENT_SECRET";
// Or your redirect URL for web based applications.
String redirectUrl = "urn:ietf:wg:oauth:2.0:oob";
String scope = "https://www.googleapis.com/auth/calendar";
// Step 1: Authorize -->
String authorizationUrl = new GoogleAuthorizationRequestUrl(clientId, redirectUrl, scope)
.build();
// Point or redirect your user to the authorizationUrl.
System.out.println("Go to the following link in your browser:");
System.out.println(authorizationUrl);
// Read the authorization code from the standard input stream.
BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
System.out.println("What is the authorization code?");
String code = in.readLine();
// End of Step 1 <--
// Step 2: Exchange -->
AccessTokenResponse response = new GoogleAuthorizationCodeGrant(httpTransport, jsonFactory,
clientId, clientSecret, code, redirectUrl).execute();
// End of Step 2 <--
GoogleAccessProtectedResource accessProtectedResource = new GoogleAccessProtectedResource(
response.accessToken, httpTransport, jsonFactory, clientId, clientSecret,
response.refreshToken);
Calendar service = new Calendar(httpTransport, accessProtectedResource, jsonFactory);
service.setApplicationName("YOUR_APPLICATION_NAME");
...
}
...
Can anyone tell how to rewrite this code so it works with the current Client Library?
You can have a look at the documentation of the Google Drive API, which is up to date:
https://developers.google.com/drive/credentials
Then it shouldn't be hard to replace the Drive scope with the Calendar scope and to instantiate the correct Calendar class for the service instead of a Drive service object.
If that situation happens again, the best to be sure you can find the latest version of code samples is to have a look directly on the website of the Google APIs Client Library for Java. You can have a look at it's wiki about auth but also have a look at the sample apps which they make sure are compiling and working with he latest version of the library (it's just harder to keep all the docs up to date sometimes)

Resources