I've installed Windows Search Service feature on Windows 2012. Now I'm testing form which should send query from Windows 2008 to Windows 2012 catalog. Windows 2008 has the Windows Search service installed too to get db driver installed/registered.
The form works properly only locally on Windows 2012
but doesn't work from Windows 2008 to Windows 2012 (remote access to catalog), Wireshark doesn't show outgoing query.
Query to local catalog (success):
("SELECT System.FileName,System.ItemPathDisplay,System.DateCreated FROM SystemIndex WHERE SCOPE='file:C:/test'", SearchConnect);
Queries to remote catalog Windows 2008 > Windows 2012 (no success)
("SELECT System.FileName,System.ItemPathDisplay,System.DateCreated FROM MyServer.SystemIndex WHERE SCOPE='file:C:/test'", SearchConnect);
("SELECT System.FileName,System.ItemPathDisplay,System.DateCreated FROM SystemIndex WHERE SCOPE='file://MyServer/C:/test'", SearchConnect);
Part of code - only select is modified during testing
{
string connectionString = "Provider=Search.CollatorDSO.1;Extended Properties='Application=Windows'";
OleDbConnection SearchConnect = new OleDbConnection();
SearchConnect.ConnectionString = connectionString;
OleDbDataAdapter SearchAdpt = new OleDbDataAdapter("SELECT System.FileName,System.ItemPathDisplay,System.DateCreated FROM SystemIndex WHERE SCOPE='file:C:/test'", SearchConnect);
SearchAdpt.Fill(searchResults);
}
Reference
MSDN - SCOPE and DIRECTORY Predicates
You are asking your local server to start a search on your local system to be done by another server ...
Use your statement with
SELECT * FROM OPENQUERY(externalServer,'script') T
Translates in your case in:
"SELECT * FROM OPENQUERY(MyServer, ' SELECT System.FileName, System.ItemPathDisplay, System.DateCreated FROM SystemIndex WHERE SCOPE=''file:C:/test'' ') T"
Related
I am trying to access SQL Server 2019 with System.Data.OleDB but I get this error:
System.Data.OleDb.OleDbException: [DBNETLIB][ConnectionOpen (Connect()).]SQL Server does not exist or access denied.
However, I am able to connect via SqlConnection.
What am I missing?
Any other configuration needed for OleDb connection to work?
I have tested using both UserID and password as well as integrated security.
I am testing in own laptop/home wifi and accessing local database, also enable tcp port 1433 specifically in window firewall.
This is my code:
var connectionString = "Provider=SQLOLEDB;Data Source=localhost;Initial Catalog=TestDB;User ID=sa;Password=sa"
//var connectionString = "Provider=SQLOLEDB;Data Source=localhost;Initial Catalog=TestDB;Integrated Security=SSPI"
OleDbConnection connection = new OleDbConnection(connectionString);
using (connection)
{
OleDbCommand cmd = new OleDbCommand("select * from TestTable", connection);
OleDbDataAdapter da = new OleDbDataAdapter(cmd);
DataSet ds = new DataSet();
da.Fill(ds);
}
The following shows how to connect to SQL Server using System.Data.OleDb.
According to Microsoft OLE DB Driver for SQL Server
Different generations of OLE DB Drivers:
There are three distinct generations of Microsoft OLE DB providers for
SQL Server.
Microsoft OLE DB Provider for SQL Server (SQLOLEDB) The Microsoft OLE DB Provider for SQL Server (SQLOLEDB) still ships as part of
Windows Data Access Components. It is not maintained anymore and it is
not recommended to use this driver for new development.
SQL Server Native Client (SNAC) Starting in SQL Server 2005 (9.x), the SQL Server Native Client (SNAC) includes an OLE DB provider
interface (SQLNCLI) and is the OLE DB provider that shipped with SQL
Server 2005 (9.x) through SQL Server 2012 (11.x).
It was announced as deprecated in 2011 and it is not recommended to
use this driver for new development. For more information about the
SNAC lifecycle and available downloads, refer to SNAC lifecycle
explained.
Microsoft OLE DB Driver for SQL Server (MSOLEDBSQL) OLE DB was undeprecated and released in 2018.
The new OLE DB provider is called the Microsoft OLE DB Driver for SQL
Server (MSOLEDBSQL). The new provider will be updated with the most
recent server features going forward.
Note:
To use the new Microsoft OLE DB Driver for SQL Server in existing
applications, you should plan to convert your connection strings from
SQLOLEDB or SQLNCLI, to MSOLEDBSQL.
One can find the connection string here.
Before proceeding, it's necessary to identify the server name where SQL Server is installed, and the instance name (if one exists).
To find the server name:
Open a cmd window, and type: hostname
To find the SQL Server instance name:
Option 1:
Open a cmd window, and type:
sc query | find /i "SQL Server"
You'll see something like the following: DISPLAY_NAME: SQL Server (SQLEXPRESS). The SQL Server instance name is within (). In this case, the SQL Server instance name is: SQLEXPRESS
Option 2
Open PowerShell, and run the following:
Get-CimInstance -Namespace Root\Microsoft\SqlServer -Query "Select Name from __Namespace where Name like 'ComputerManagement%'" | ForEach-Object { $sqlMgmtVer = $_.Name; Get-CimInstance -Namespace Root\Microsoft\SqlServer\$sqlMgmtVer -Class FileStreamSettings |Select-Object InstanceName }
Option 3
Open PowerShell, and run the following:
Get-CimInstance -Namespace Root\cimv2 -Query "Select DisplayName from Win32_Service where DisplayName like 'SQL Server%'" | ForEach-Object {$dName = $_.DisplayName; if ($dName -match "^SQL Server \((?<instanceName>.*)\)$") { $matches["instanceName"]; }}
Now that we've gathered the necessary information, try the following:
// '.' can be used instead of "localhost" or "127.0.0.1"
// SQL Server instance name = SQLExpress
private string _connectionStr = #"Provider=MSOLEDBSQL;Server=.\SQLExpress;Database=TestDB;UID=test;PWD=mySecretPassword;";
public DataTable GetProductInfo()
{
DataTable dt = new DataTable();
using (OleDbConnection con = new OleDbConnection(_connectionStr))
{
using (OleDbDataAdapter da = new OleDbDataAdapter("select * from Product", con))
{
da.Fill(dt);
return dt;
}
}
}
Resources:
Microsoft OLE DB Driver for SQL Server
Connection Strings - SQL Server OLE DB
System.Data.OleDb Namespace
Filtering output using "Where-Object" in Powershell
Windows PowerShell: Extracting Strings Using Regular Expressions
Powershell: The many ways to use regex
Chapter 7 - Working with WMI
I use ASP.NET 4.6.1 in Windows Server 2008 r2 using Indexing Server.
I use Microsoft OLE DB Provider for Microsoft Indexing Service, same Provider MSIDXS
Now, I want use Windows Server 2012 r2.
Indexing Service is no longer supported as of Windows XP and is
unavailable for use as of Windows 8. Instead, use Windows Search for
client side search and Microsoft Search Server Express for server side
search.
How use using Microsoft Search in ASP.NET?
I'm confused: I use Windows Search Server or Windows Search Service ?
Which OLE DB provider is required ?
How install Windows Search Server ?
How install Windows Search Service ? (maybe feature in Windows 2012 R2)
Downloading and installing Windows Search Server does not install the
OLE DB provider. Neither does installing the Windows SDK. The provider
is installed when the Windows Search Service is installed.
On Win7/8 desktop OS, this is installed be default (I believe). On
server Windows Server 2012, you have to enable the feature.
My code using Indexing Server in Windows 2008 R2 + ASP.NET:
// Catalog Name
string strCatalog = txtNombreCatalogo.Text;
string strQuery = "";
strQuery = "Select DocTitle,Filename,Size,PATH,URL";
strQuery += ", DocAuthor, vpath, Write, Rank, Create, Characterization, DocCategory";
strQuery += " from Scope() where FREETEXT('" + txtNombreFichero.Text + "')";
// txtNombreFichero.Text is the word that you type in the text box to query by using Indexing Service.
string connstring = "Provider=MSIDXS;Integrated Security .='';Data Source=" + strCatalog;
//connstring = "Provider=MSIDXS.1;Integrated Security .='';Data Source=" + strCatalog;
var conn = new System.Data.OleDb.OleDbConnection(connstring);
conn.Open();
var cmd = new System.Data.OleDb.OleDbDataAdapter(strQuery, conn);
var testDataSet = new System.Data.DataSet();
cmd.Fill(testDataSet, "SearchResults");
DataView source = new DataView(testDataSet.Tables[0]);
dgResultados.DataSource = source;
dgResultados.DataBind();
I'm confused: I use Windows Search Server or Windows Search Service ?
You use Indexing search(https://msdn.microsoft.com/en-us/library/ee805985(v=vs.85).aspx).
Which OLE DB provider is required ?
For use Windows Search Service use "Provider=Search.CollatorDSO;Extended Properties='Application=Windows'; Data Source=(local);"
How install Windows Search Server ?
For use Windows Search Server you should download and install Microsoft Search Server(based on sharepoint) https://www.microsoft.com/en-us/download/details.aspx?id=18914.
I'm in Visual Studio 2013, using SQL Server Express 2012, on Windows 7 OS.
With C# code, I CAN connect to the database and query. For example:
using (SqlConnection sqlConnection = new SqlConnection("server=MYSERVER\\SQLEXPRESS; Trusted_Connection=yes; database=MyDatabase; connection timeout=30"))
{
using (SqlCommand cmd = new SqlCommand())
{
cmd.CommandText = "SELECT count(*) FROM tblData";
cmd.Connection = sqlConnection;
sqlConnection.Open();
int count = (int)cmd.ExecuteScalar();
Console.WriteLine(count); // I get the correct answer.
}
}
That works. My problem is that if I use Server Explorer within Visual Studio, I cannot connect to the database via that route. In the Add Connection, MyServer does appear in the server dropdown, but the database dropdown is empty. When I click Test Connection or OK (leaving Database empty or entering MyDatabase), I get the error: Server was not found or was not accessible.
So I can connect via C# code, but not with Server Explorer. What am I missing?
Thanks.
You have a named instance (SQLExpress) of the SQL Server. In the connections window, try typing in the server name as:
MYSERVER\SQLEXPRESS
I've been having issues trying to connect mySQL Server MC9190 (barcode scanner) to a SQL Server database and I've been having issues. It works fine when I run on my desktop, but when I try to run it on my pocket PC that runs on Windows CE 6.0 it throws the error:
System.TypeLoadException was unhandled
Message="File or assembly name 'System.Data.SqlClient, Version=3.0.3600.0,Culture=neutral, PublicKeyToken=3BE235DF1C8D2AD3', or one of its dependencies, was not found."
Anyone have any idea how to connect my pocket pc to the database so I can input the data I collect from the scanner into the database? Here is my code when I'm trying to connect to the database:
SqlConnection myConnection = new SqlConnection("Server=*****\\SQLEXPRESS;DATABASE=testing;Trusted_Connection=yes;connection timeout=15;user id=************");
try
{
//open the server
myConnection.Open();
//Insert values passed into the metod
SqlCommand myCommand = new SqlCommand("INSERT INTO test (Part_Number, total, number_of_packs, dunsNumber, serialNumber, truck_number) VALUES (#Part_Number,#total,#number_of_packs,#dunsNumber,#serialNumber,#truck_number)", myConnection);
myCommand.Parameters.AddWithValue("#Part_Number", partNumber);
myCommand.Parameters.AddWithValue("#total", total);
myCommand.Parameters.AddWithValue("#number_of_packs", numOfPacks);
myCommand.Parameters.AddWithValue("#dunsNumber", dunsNumber);
myCommand.Parameters.AddWithValue("#serialNumber", serialNumber);
myCommand.Parameters.AddWithValue("#truck_number", laneNumber);
//execute the query
myCommand.ExecuteNonQuery();
myConnection.Close();
}
As far as I'm aware, you cannot use Express on it. You will need to use Compact.
Here is a tutorial on setting up SQL CE with C# Apps.
http://www.dotnetperls.com/sqlce
Here are the install instructions for CE 6 (MS SQL Compact needs an extra install).
http://msdn.microsoft.com/en-us/library/13kw2t64(v=vs.90).aspx
Edit: --> this is assuming you are trying to use a database on the machine itself. Otherwise this won't be your answer.
I am using 64-bit Windows Server 2008 with SQL Server 2008. And Using VS2008 + C# + .Net 2.0 + IIS 7.0 + ASP.Net. When executing the following statement, I met with the following error (the error occurs when accessing an aspx page), I am not sure whether it is 64-bit system specific issue?
Sys.WebForms.PageRequestManagerServerErrorException: unregistered OLE DB access interface "Microsoft.Jet.OLEDB.4.0"
StringBuilder sb = new StringBuilder();
sb.AppendLine("select * from OPENROWSET('MICROSOFT.JET.OLEDB.4.0','Excel 8.0;HDR=YES;DATABASE=" + s_path.Trim() + "',sheet1$) where name is not null"); //e:\\test1.xls
DataSet ds = SqlUtil.ExecuteDataset(Database.StrConn, CommandType.Text, sb.ToString());
if (ds.Tables[0].Rows.Count > 0)
{
GridView_Tlinkmans.DataSource = ds;
GridView_Tlinkmans.DataBind();
}
You have one or 2 issues:
You are querying OPENROWSET in SQL Server and you have x64 SQL Server, you may need the MDAC to bridge SQL Server to ODBC/OLEDB. However, this says it is part of the OS for Win 2008+. I've had to install on Win 2003
Then you probably need this which is the closest to JET I know of: Microsoft Access Database Engine 2010 Redistributable
YMMV