We are using windows search to search for document on a remote share, after applying security update KB4022726 this functionality breaks.
Our implementation is using oledb connector for windows search in C#
Are there any workarounds besides uninstalling KB4022726?
Update:
CVE-2017-8543 might be related.
Sample program - that failes efter install of KB4022726
using System;
using System.Data.OleDb;
namespace windowssearchtest
{
class Program
{
static void Main(string[] args)
{
var computer = "searchserver";
var filepath = #"documents";
var query = $#"
Select System.Itemname
FROM {computer}.systemindex
WHERE SCOPE='file:\\{computer}\{filepath}'";
const string ConnectionString = "Provider=Search.CollatorDSO;Extended Properties=\"Application=Windows\"";
OleDbDataReader myDataReader = null;
OleDbConnection myOleDbConnection = new OleDbConnection(ConnectionString);
OleDbCommand myOleDbCommand = new OleDbCommand(query, myOleDbConnection);
myOleDbCommand.CommandTimeout = 180;
try
{
myOleDbConnection.Open();
myDataReader = myOleDbCommand.ExecuteReader();
if (myDataReader != null && myDataReader.HasRows)
{
Console.WriteLine($"HasRows: {myDataReader.HasRows}");
while (myDataReader.Read())
{
}
}
}
catch (Exception e)
{
Console.WriteLine(e.ToString());
}
}
}
}
Error:
System.Data.OleDb.OleDbException (0x80004005): Uspecificeret fejl
ved System.Data.OleDb.OleDbDataReader.ProcessResults(OleDbHResult hr)
ved System.Data.OleDb.OleDbDataReader.GetRowHandles() ved
System.Data.OleDb.OleDbDataReader.ReadRowset() ved
System.Data.OleDb.OleDbDataReader.Read() ved
windowssearchtest.Program.Main(String[] args) i
C:\projects_local\windowssearchtest\windowssearchtest\Program.cs:linje
48
Update 2017-06-26
I have also reproduced this error on a local machine running win10 - 1703
Windows search still works, but will throw an error when you reach the end of the resultset, or if empty on .ExecuteReader()
We made a hack to work around this, i will not recommend this:
//pseudo code
while (Wrap(myDataReader))
<snip>
function Wrap(myDataReader)
{
try
{
return myDataReader.Read();
}
catch (ex)
{
if(ex.HResult == -2147467259) return false; //0x80004005
throw;
}
}
It looks like the issue has been fixed in the latest Optional Updates from MS:
Win7, Server 2008:
https://support.microsoft.com/en-us/help/4022168/windows-7-sp1-windows-server-2008-r2-sp1-update-kb4022168
Win 8.1, Server 2012:
https://support.microsoft.com/en-us/help/4022720/windows-8-1-windows-server-2012-r2-update-kb4022720
Have installed these updates on my test servers (2008, 2012) and not getting that error now!
Related
I am trying to connect to a sample database I have created in Azure using C# (.NET Core 3.1)
I have enabled my IP address within Azure's Firewall rules.
I am able to use VS2019's SQL Server Object Explorer to connect and view the database within with no problems.
However, when I run a simple C# app on the same PC to execute a query to count the number of records in a table, it throws the following exception at the point where the connection is opened (conn.Open());
A network-related or instance-specific error occurred while establishing a connection to SQL Server. The server was not found or was not accessible. Verify that the instance name is correct and that SQL Server is configured to allow remote connections. (provider: TCP Provider, error: 0 - The requested address is not valid in its context.)
The C# code;
using System;
using System.Data.SqlClient;
namespace AzureSql2
{
class Program
{
static void Main(string[] args)
{
string connStr = " Server=tcp:beaconsqlsql.database.windows.net,1433;Initial Catalog=MRP2;Persist Security Info=False;User ID=beaconadmin;Password=********;MultipleActiveResultSets=False;Encrypt=True;TrustServerCertificate=False;Connection Timeout=30;";
Console.WriteLine("Building connection");
try
{
using (var conn = new SqlConnection(connStr))
{
Console.WriteLine("Creating command");
using (var command = conn.CreateCommand())
{
command.CommandText = "SELECT COUNT(*) FROM [dbo].[Table]";
Console.WriteLine("Opening connection");
conn.Open();
Console.WriteLine("Reading database");
using (var reader = command.ExecuteReader())
{
while (reader.Read())
{
Console.WriteLine("Record count: {0}", reader.GetInt32(0));
}
}
}
}
}
catch (Exception ex)
{
Console.WriteLine("Exception: " + ex.Message);
}
Console.WriteLine("Press Enter to exit");
Console.ReadLine();
}
}
}
I've tried temporarily turning off the firewall on my PC, but that made no difference.
The fact that SQL Server Object Explorer can connect but the C# code cannot makes it sound like there's a problem with the C# code, but I can't see any differences between it and the samples I've looked at.
I created one Azure SQL database and allowed my client IP like below :-
I created one .Net Console application and ran your code, I replaced
using System.Data.SqlClient
with
using Microsoft.Data.SqlClient
You can use any of the above packages.
Copied connection string from Azure Portal > Azure SQL server > Connection string refer below :-
C# Code:-
using System;
using System.Linq.Expressions;
using Microsoft.Data.SqlClient;
namespace AzureSql2
{
class Program
{
static void Main(string[] args)
{
string connStr = "Server=tcp:sqlservername.database.windows.net,1433;Initial Catalog=sqldbname;Persist Security Info=False;User ID=username;Password=password;MultipleActiveResultSets=False;Encrypt=True;TrustServerCertificate=False;Connection Timeout=30;";
Console.WriteLine("Building connection");
try
{
using (var conn = new SqlConnection(connStr))
{
Console.WriteLine("Creating command");
using (var command = conn.CreateCommand())
{
command.CommandText = "SELECT * FROM Products";
Console.WriteLine("Opening connection");
conn.Open();
Console.WriteLine("Reading database");
using (var reader = command.ExecuteReader())
{
while (reader.Read())
{
Console.WriteLine("Record count: {0}", reader.GetInt32(0));
}
}
}
}
}
catch (Exception ex)
{
Console.WriteLine("Exception: " + ex.Message);
}
Console.WriteLine("Press Enter to exit");
Console.ReadLine();
}
}
}
Output :-
I tried to run the code with the connection string format you mentioned in the comments :-
Data Source=azuresqlservername.database.windows.net;Initial Catalog=databasename;User ID=siliconuser;Password=password;Connect Timeout=30;Encrypt=True;TrustServerCertificate=False;ApplicationIntent=ReadWrite;MultiSubnetFailover=False
And I was able to run the same code above and got the desired output:-
When I tried to change the Azure SQL server name in the connection string, I got the same error code as yours, refer below :-
Verify if your connection string has any syntax missing and validate it from Azure Portal.
I ended up taking a copy of the project home and running it on my home PC, and it worked correctly and reliably (after telling Azure to allow that IP address as well)
It turned out the answer was embarrassingly obvious - in addition to the standard Windows 10 firewall, my work PC is running another virus protection/firewall software, and that also needed to be told to allow the app thru.
Definitely one to remember for next time... Although I am kind of intrigued that on two occasions (once mentioned above, once afterwards) out of a few hundred attempts the app did manage to get thru and connect.
Thank you everyone for your answers and help.
I have the following problem. I want to connect my C# application with our SAP server, which works fine, but in addition, I want to a execute an RFC and read the output with ExecuteReader().
using Microsoft.Data.SapClient;
namespace SAPconnect2
{
class Program
{
static void Main(string[] args)
{
string connstr = "ASHOST=xxx; SYSNR=00; CLIENT=100; LANG=EN; USER=xxx; PASSWD=xxx;";
using (SapConnection conn = new SapConnection(connstr))
{
conn.Open();
using (SapCommand cmd = (SapCommand)conn.CreateCommand())
{
cmd.CommandText = "exec zrfc_test";
using (SapDataReader dr = (SapDataReader)cmd.ExecuteReader())
{
}
}
}
}
}
}
But when I execute the programme, I get the following error: additional information: Incorrect token found, expected a token of the following type: Describe, Execute, Select. [XtractQL/Command]
I also tried to follow this guide: https://msdn.microsoft.com/en-us/library/cc185499(v=bts.10).aspx
But when I remove (SapCommand) before conn.CreateCommand() and (SapDataReader) before cmd.ExecuteReader(), I generate error CS0266.
What do I have to do, to get this programme running?
I'm trying to create an installer file that installs a database using install shield 2015.
I'm following this link
Walkthrough: Using a Custom Action to Create a Database at Installation
Since this link refers to an older install shield I didn't managed to make it work. I have created an install file in my main windows form application, which you can see in the below code.
public partial class DeployInstaller : System.Configuration.Install.Installer
{
System.Data.SqlClient.SqlConnection masterConnection = new System.Data.SqlClient.SqlConnection();
public DeployInstaller()
{
InitializeComponent();
}
private string GetSql(string Name)
{
try
{
// Gets the current assembly.
Assembly Asm = Assembly.GetExecutingAssembly();
// Resources are named using a fully qualified name.
Stream strm = Asm.GetManifestResourceStream(Asm.GetName().Name + "." + Name);
// Reads the contents of the embedded file.
StreamReader reader = new StreamReader(strm);
return reader.ReadToEnd();
}
catch (Exception ex)
{
//Interaction.MsgBox("In GetSQL: " + ex.Message);
throw ex;
}
}
private void ExecuteSql(string Sql)
{
masterConnection.ConnectionString = "data source=.//SQLEXPRESS;initial catalog=master;integrated security=True; MultipleActiveResultSets=True; Application Name=EntityFramework";
System.Data.SqlClient.SqlCommand Command = new System.Data.SqlClient.SqlCommand(Sql, masterConnection);
// Initialize the connection, open it, and set it to the "master" database
Command.Connection.Open();
try
{
Command.ExecuteNonQuery();
}
finally
{
// Closing the connection should be done in a Finally block
Command.Connection.Close();
}
}
protected void AddDBTable()
{
try
{
// Creates the database.
//ExecuteSql("master", "CREATE DATABASE " + strDBName);
// Creates the tables.
ExecuteSql( GetSql("sql.txt"));
}
catch (Exception ex)
{
// Reports any errors and abort.
//Interaction.MsgBox("In exception handler: " + ex.Message);
throw ex;
}
}
public override void Install(System.Collections.IDictionary stateSaver)
{
base.Install(stateSaver);
AddDBTable();
}
}
Supposedly this piece of code provides the user with the ability of doing both the installation of the system and the corresponding database. For some reason only the system is being installed. When attempting to install the database, something is preventing from successfully completing. Unfortunately, I cannot pinpoint the reason why because it doesn't give out an error with the reason. It could be that its never being started or that I did something wrong.
Any guide would be appreciated.
I try to work with a SQL Server CE 4.0 database with my simple console app but it is not working on one of my machine.
OS: Windows Server 2003 Enterprise x64 Edition with Service Pack 2
I have also installed Microsoft SQL Server Compact 4.0 and used its dll (System.Data.SqlServerCe.dll) but every time I got following error
Unable to load the native components of SQL Server C
ADO.NET provider of version 8080. Install the correc
act. Refer to KB article 974247 for more details.
Here is my code
try
{
Console.WriteLine("Started");
var sqlConnectionString = "Data Source=c:\\tde\\22\\22.tde;password='sanjayraj';mode=Read Write;max database size=4091;temp file max size=4091";
_connection = new SqlCeConnection(sqlConnectionString);
_connection.Open();
var sqlStatement = "SELECT * FROM InfoStores WHERE Location = 'Source'";
IDbCommand newCommand = new SqlCeCommand
{
CommandText = sqlStatement,
Connection = _connection,
CommandType = CommandType.Text
};
using (IDataReader reader = newCommand.ExecuteReader())
{
while (reader.Read())
{
Console.WriteLine(reader[0].ToString());
}
}
}
catch (Exception ex)
{
Console.WriteLine("Error Occured");
Console.WriteLine(ex.Message);
Console.ReadKey();
}
Console.WriteLine("Finished");
Console.ReadKey();
You a referenceing the wrong version of System.data.SqlServerCe.dll, use the one in the C:\Program Files (x86)\Microsoft SQL Server Compact Edition\v4.0\Desktop folder
I'm a real noob in .NET and i'm trying to link a simple command line application (in C#) with a SQL server database. I'm now able to connect the program with the database but not to recover the data that are in it. Here is my code :
using System;
using System.Data;
using System.Data.SqlClient;
namespace ConsoleApplication1
{
class Program
{
static void Main()
{
string connectionString = GetConnectionString();
string queryString = "SELECT USER_ID FROM dbo.ISALLOCATEDTO;";
using (SqlConnection connection = new SqlConnection(connectionString))
{
SqlCommand command = connection.CreateCommand();
command.CommandText = queryString;
try
{
connection.Open();
SqlDataReader reader = command.ExecuteReader();
int i = 0;
while (reader.Read())
{
i++;
Console.WriteLine("Field "+i);
Console.WriteLine("\t{0}",reader[0]);
}
reader.Close();
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
}
}
//Console.WriteLine("Hello world");
string x = Console.ReadLine();
}
static private string GetConnectionString()
{
return "Data Source=FR401388\\SQLEXPRESS;Initial Catalog=Test;";
+ "Integrated Security=SSPI";
}
}
}
But when i'm running it and even if my table is not empty (I've seen it in the sql server studio), I cannot recover the data by using the read() method.
What I've done so far : try to change the name of the datatable with a fake one : the datatable is not found (so the link between sql server database and programm seems to be valid).
I'm using Windows Authentication in sql server, dunno if it's changing anything... (Once again : i'm very new to all of that).
Thanks !
Your code should work.
A possible cause is: You are looking at a different database.
This is quite common if you use Server Explorer inside VS with a connectionstring different from the one used in code.