Any EncryptionMode in FluentFTP? - c#

I need to apply encryption mode in FluentFTP's ftp.
The syntax "EncryptionMode" don't exist in .net 6.
var conn = new FtpClient();
conn.EncryptionMode = FtpEncryptionMode.Explicit;
How should I apply EncryptionMode in FluentFTP's ftp in .net6?
Thank you?

Related

Best way to retrieve pdf attachments saved as varbinary(max) from SQL Server and save to a local drive using C#

I have few thousands attachments saved in a SQL Server database with column datatype varbinary(max). I want to retrieve all these files and save them to a local drive.
What is the best way to achieve that? I am not looking for code specifically but trying to understand all options so I can do this in C#.
Suggestions are appreciated. Thank you
You can do any of the followings:
Write a SQL script which will read the data from the table and save those to the disk. Here is how that can be done
You can write a C# script which will connect to the Database, Read and store the data as a file to a disk
Use the Id of the table as part of the file name to make it unique if you are storing all the files to a single folder.
Here's example code.
Note, the namespace System.Data.SqlClient is not referenced by a .NET Core project by default as done by .NET Framework; you have to manually add the System.Data.SqlClient NuGet package to the project.
using System.Data.SqlClient;
var connectionString = "Data Source=localhost;Initial Catalog=MyDatbase;Integrated Security=True;";
var outputFolder = #"C:\temp\";
using var conn = new SqlConnection(connectionString);
conn.Open();
var query = "select DocumentId, Contents from DocumentFile where ID >= 1234";
using var cmd = new SqlCommand(query);
cmd.Connection = conn;
var reader = cmd.ExecuteReader();
if (!reader.HasRows) throw new Exception("No rows!");
while (reader.Read())
{
var fileName = $"{reader["DocumentId"]}.pdf";
var data = (byte[])reader["Contents"];
if (data == null) throw new Exception("Contents is null");
using var writer = new BinaryWriter(File.OpenWrite(Path.Combine(outputFolder, fileName)));
writer.Write(data);
}

SQL Server CE: Suppress modifications of database file?

we have an application that has a local SQL Server CE database file. When we open the database, but don't do any changes to it, the database file is changed anyway:
using (var connection = new SqlCeConnection("Data Source='data.sdf';File Mode='Shared Read';Encrypt=FALSE;LCID=1033"))
{
connection.Open();
using (var context = new DataContext(connection))
{
}
}
This changes some bytes at the very beginning of the sdf-file.
Is there any way to prevent this?
Yes, you can enable read only mode in the connection string. Also you may need to specify a temp path in this case:
string connectionString = ...;Mode = Read Only;Temp Path= ...;
More info.

ORA-01005 error connecting with ODP.Net

I am trying to access an Oracle database (version 10.2.0.4.0) using the following code but an "ORA-01005: Null password given; logon denied" exception is raised by the connection when it's open method is called.
var connBuilder = new OracleConnectionStringBuilder();
connBuilder.DataSource = "(DESCRIPTION =(ADDRESS_LIST =(ADDRESS = (PROTOCOL = TCP)(HOST = MyHost.Address)(PORT = ####)) )(CONNECT_DATA =(SERVICE_NAME = MyService)))";
connBuilder.UserID = "validUserId";
connBuilder.Password = "validPassword";
connBuilder.PersistSecurityInfo = true;
var connString = connBuilder.ToString();
using (var con = new OracleConnection(connString))
{
con.Open();
}
If I change the username then I receive the following instead; "ORA-01017: invalid username/password; logon denied" and this is also the case if I change the open call on the connection with con.OpenWithNewPassword("validPassword");
If I try with the deprecated Oracle client it connects with no problems:
using (var depCon = new System.Data.OracleClient.OracleConnection
("Data Source=MyHost.Address:####/MyService;Persist Security Info=True;
User ID=validUsername;Password=validPassword;Unicode=True"))
{
depCon.Open();
}
I'd (obviously) like to use the latest Odp.Net drivers but can't seem to get past this issue. Has anybody got any ideas?
Take a look at this thread for an issue regarding FIPS compliance:
https://community.oracle.com/thread/2557592?start=0&tstart=0
Also:
Oracle.ManagedDataAccess and ORA-01017: invalid username/password; logon denied
Does it work when you do it like this:
var connBuilder = new Common.DbConnectionStringBuilder();
connBuilder.Add("Data Source", "(DESCRIPTION =(ADDRESS_LIST =(ADDRESS = (PROTOCOL = TCP)(HOST = MyHost.Address)(PORT = ####)) )(CONNECT_DATA =(SERVICE_NAME = MyService)))";
connBuilder.Add("User Id", "validUserId");
connBuilder.Add("Password", "validPassword");
Which version of ODP.NET do you use? There are known issues when you connect to a "new" Oracle database with case-sensitive passwords using an "old" ODP.NET provider, see here: https://community.oracle.com/message/2198228
In order to verify run this command on your database:
ALTER SYSTEM SET SEC_CASE_SENSITIVE_LOGON = FALSE;
The issue with case sensitivity and the ODP.Net drivers and different DB versions should be a simple fix. Enclose your connectionstring password in quotes(") such as Password=\"password\"; and this should keep the password case

Invalid ConnectionString format for parameter "Version 3"

I have created the object & also provided with the connection string (not sure whether it is accurate or not).
I am using ado.net 2.0/3.5 provider for sqlite in c#.
SQLiteTransaction trans;
SQLiteConnection con = new SQLiteConnection();
con.ConnectionString = #"Data Source = pathology.db ; Version 3";
con.Open();
trans = con.BeginTransaction();
int retval = 0;
After running above code I am getting invalid connection string format for parameter Version 3 on con.Open(); .
Need some guidance on it as I m a beginner using visual studio c# & sqlite.
Thank you!!
Should be Version=3;. Also you might need to specify full path to db file.
There is good site for connection strings: http://www.connectionstrings.com/sqlite/

MongoDB with C#.net

I am Very new with MongoDB,I m using windows7 32bit,downloaded mongo exe files from http://www.mongodb.org/display/DOCS/Quickstart+Windows
And downloaded mongodb.dll also
Mongo mongo = new Mongo();
mongo.Connect();
gives me the error
Failed to connect to server localhost:27017
Is i m missing something,plz let me know
You should use
var connectionString = "mongodb://localhost/?safe=true";
var server = MongoServer.Create(connectionString);
var database = server.GetDatabase("test");

Categories