How to use EntityFramework BulkInsert? [duplicate] - c#

This question already has an answer here:
How to use EntityFramework.BulkInsert?
(1 answer)
Closed 8 years ago.
I'm trying to use, this, but the system can not find the methods of lib...
Nothing that is specified in the documentation of the lib. is running, for example: GetContext() is not found, the own BulkInser is not found .... I put at the top of my code the Using of lib, but nothing works .....
How I can make to use that Lib ? ( I'm using the VS2013 )
My code:
using EntityFramework.BulkInsert.Extensions;
using (var transactionScope = new TransactionScope())
{
var ctx = new MyDBCon.MyDBDataContext();
ctx.BulkInsert(linhas); // error in BulkInsert ( method not found )
ctx.SubmitChanges();
transactionScope.Complete();
}

You need to include the library...
using EntityFramework.BulkInsert.Extensions;
Add this to the top of your class.

Related

How to create a file relative to Program.cs [duplicate]

This question already has answers here:
Get the application's path
(21 answers)
Closed 3 months ago.
The community reviewed whether to reopen this question 3 months ago and left it closed:
Original close reason(s) were not resolved
I want to create a file relative to Program.cs. This code in case of VSCode works correct:
string myFile1 = #".\temp1.txt";
File.Create(myFile1);
string myFile2 = "./temp2.txt";
File.Create(myFile2);
but Visual Studio IDE 2022 creates file in:
`MyProject\bin\Debug\net6.0`
Is there any universal solution?
You can include the following method anywhere within your project:
using System.Runtime.CompilerServices
public static string GetSourceFilePathName( [CallerFilePath] string? callerFilePath = null )
=> callerFilePath ?? "";
Then, you can invoke that method from your Program.cs, and it will give you C:\Users\YOU\Documents\Projects\MyProject\Program.cs.
I suppose you know what to do from there.

Configure Application Pool .NET CLR Version using C# .NET Core [duplicate]

This question already has answers here:
Set .NET CLR Version to No Managed Code
(3 answers)
Closed 2 years ago.
When trying to assign a Managed RunTime Version version with this code:
using (ServerManager serverManager = new ServerManager())
{
ApplicationPool newAppPool = serverManager.ApplicationPools.Add("HICS");
newAppPool.ManagedRuntimeVersion = "No Managed Code";
}
It sets the version to "No Managed Code", but it's not the right selection. I end up with this:
If I select the other "No Managed Code", the App Pool works just fine. Why is it creating a duplicate option? How can I select the existing "No Managed Code"? Using C# code of course..
Try setting it to "", like in this answer. It should still work, although they are setting this value in a slightly different method.
using (ServerManager serverManager = new ServerManager())
{
ApplicationPool newAppPool = serverManager.ApplicationPools.Add("HICS");
newAppPool.ManagedRuntimeVersion = "";
}

.xmla deployment to SQL using C#

I use Invoke-ASCmd in PowerShell right now to create a database in SQL Server, like this:
Invoke-ascmd -Query $MyScript -Server $ASServer
Where $MyScript is a string holding the contents of an .xmla file that I read in previously.
This works great. Now I need to do something similar in C#, but am unable to find a simple solution like the one that exists in PowerShell.
I see some people using a Microsoft DLL called Microsoft.AnalysisServices.XMLA.dll, but it's not supported, and the class in question is "internal", so I can't even reference it.
I found this DLL Microsoft.AnalysisServices.AdomdClient.dll while searching around, but don't see any of the classes being relevant to what I need: https://learn.microsoft.com/en-us/dotnet/api/microsoft.analysisservices.adomdclient?view=analysisservices-dotnet
using Microsoft.AnalysisServices.AdomdClient;
try
{
var xmlaFileContents = File.ReadAllText("path/to/your/file.xmla");
using (AdomdCommand cmd = conn.CreateCommand())
{
cmd.CommandText = xmlaFileContents;
cmd.ExecuteNoQuery();
}
}
catch(Exception)
{
}
** please note that I have not run this code **
As the AdomdConnection is inherited from IDbConnection, it's pretty similar to how the SqlConnection works, and therefor, similar syntax can be used, as #jogi presented for you.
I wrote a PS function a few years back which we use in TFS builds. It uses the .NET assemblies rather than the PS layer, so I figured since you seem savvy in PS, you can perhaps get something out of it. Still essentially the same as what #jogi wrote, only wrapped in PS.
function Invoke-XmlaScript {
[CmdletBinding()] param (
[Parameter(Mandatory=$true)][ValidateNotNullOrEmpty()][string]$ServerInstance,
[Parameter(Mandatory=$true)][ValidateNotNullOrEmpty()][string]$XmlaScript
)
process {
$connection = New-Object Microsoft.AnalysisServices.AdomdClient.AdomdConnection("Data Source=$ServerInstance;Provider=MSOLAP.4;Integrated Security=SSPI;Impersonation Level=Impersonate;")
$connection.Open()
try {
$command = $connection.CreateCommand()
$command.CommandTimeout = 20000
$command.CommandType = [System.Data.CommandType]::Text
$command.CommandText = $Xmla
$reader = $command.ExecuteXmlReader()
if($reader.Read()) {
Write-Output $reader.ReadOuterXml()
}
}
catch { }
$connection.Dispose()
}
}

Add custom file properties programmatically [duplicate]

This question already has answers here:
Add new metadata properties to a file
(1 answer)
Custom File Properties
(4 answers)
Closed 4 years ago.
I need to add custom file properties (see here) to thousands of files programmatically.
The WindowsAPICodePack can get/set existing file properties, but it seems it can not add custom properties?!?
Here the code that works based on Add new metadata properties to a file:
You must reference the DSOFile.dll which can be downloaded from Microsoft here:
Microsoft Developer Support OLE File Property Reader 2.1 Sample
using DSOFile;
OleDocumentProperties myFile = new DSOFile.OleDocumentProperties();
myFile.Open(#"c:\temp\B30700.asm", false, DSOFile.dsoFileOpenOptions.dsoOptionDefault);
bool property_exists;
object prop_value;
prop_value = "999";
//Then check if there's already a property like the one you want to create
property_exists = false;
foreach (DSOFile.CustomProperty property in myFile.CustomProperties)
{
if (property.Name == "Your Property Name")
{
//Property exists
//End the task here (return;) oder edit the property
property_exists = true;
property.set_Value(prop_value);
}
}
if (!property_exists)
myFile.CustomProperties.Add("Your Property Name", ref prop_value);
myFile.Save();
myFile.Close(true);

Subsonic: Using SharedDbConnectionScope together with TransactionScope seems to be broken

Using the code below, the expected behavior is that the database won't reflect the update since ts.Complete() is never called but the updates seems to go through. But if I leave out the SharedDbConnectionScope then the expected behavior is seen. Is there a problem with SharedDbConnectionScope? Btw I am using Subsonic 2.2
using (SharedDbConnectionScope sharedConnectionScope = new SharedDbConnectionScope())
{
using (TransactionScope ts = new TransactionScope())
{
// update here
}
}
Found out the problem. The docs on Subsonic appears to be wrong. If I wrap TransactionScope over SharedDbConnectionScope then it works fine. The right way should be:
using (TransactionScope ts = new TransactionScope())
{
using (SharedDbConnectionScope sharedConnectionScope = new SharedDbConnectionScope())
{
// update here
}
}
Edit: As mentioned by firestorm, SharedDbConnectionScope doesn't seem to work in Subsonic 2.2. So the only solution seems to be to install MsDts and don't use SharedDbConnectionScope.
I don't think SharedDbConnectionScope works at all in Subsonic 2.2.
The whole idea as far as I can see with the object is that when you use it you don't need to have MsDts installed on the server. I couldn't get this to work at all!
When you install MsDts then you don't need SharedDbConnectionScope any more that's why your code works when it gets created after TransactionScope.

Categories

Resources