Querying a remote Indexing Service database - c#

I'm trying to search the Indexing Service of a remote Windows 2003 server from ASP.NET. There's sample code for this on the MS site, but only for local searches. Here's what I've got so far; the remote server in this example is called "indexserver", isn't on a domain, and has a index called "system":
OleDbConnection conn = new OleDbConnection();
conn.ConnectionString = "Provider=MSIDXS;User ID=administrator;Password=Password";
OleDbCommand cmd = conn.CreateCommand();
cmd.CommandText= "SELECT * FROM indexserver.system..FILEINFO";
conn.Open();
cmd.ExecuteReader();
Running this gives me the error "Multiple-step OLE DB operation generated errors. Check the OLE DB status if available. No work was done".
Does anyone know how to get this working? All I need to do is query the Index for a filename and get the path of that file back.

Never mind, I discovered that Windows Indexing Service is somewhat depreciated,and Windows Search seems to be the way to go...

Related

Azure function Connecting to Oracle database

I have a console application to connect and update a record on oracle. This works fine. But after copying the same function onto an azure function, I am getting Connection Timeout issue. Does anybody know if there are some set ups or other configuration required on Azure?
Below is my code block:
OracleConnection con = new OracleConnection();
OracleConnectionStringBuilder ocsb = new OracleConnectionStringBuilder();
ocsb.Password = "xxxxx";
ocsb.UserID = "xxxxx";
ocsb.DataSource = "xxxxxxx";
con.ConnectionString = ocsb.ConnectionString;
con.Open();
OracleCommand cmd = con.CreateCommand();
cmd.CommandText = "UPDATE PRODUCTS SET STATUS = 20 WHERE STATUS = '30'";
cmd.CommandTimeout = 100000;
cmd.ExecuteNonQuery();
con.Close();
Partially answer for connecting to on-premise service like Oracle-db from Azure Functions, there is an existing SO thread had answered it, which you can refer to.
So first, you must make sure networking access to on-premise server available. Following this article about using Hybrid Connections.
Then, if you want to query oracle database via odbc, the oracle odbc driver must be installed on the client-side.
THanks for your help above,
The issue occurred because I made an update on the oracle console but did not commit. Unlike sql server, when you run an update statement, you should also run the 'commit' line of code.

Local Database fails and crashes in VS2017

I'm trying to set up a local database (Service-based Database) in my C# app. When I intially adds the database to the project, I can see it and edit tables in both VS and SSMS, but when I try to connect to it programmatically, I get this error:
"Cannot open database \"[DataDirectory]DATABASE.MDF\" requested by the login. The login failed.\r\nLogin failed for user 'DESKTOP-MM6AR72\\majbom'."
And after that, the database is gone from both VS and SSMS.
I'm connecting this way:
using(SqlConnection conn = new SqlConnection("Data Source=(localdb)\\MSSQLLocalDB;Initial Catalog=[DataDirectory]DATABASE.MDF;Integrated Security=True;Connect Timeout=30;Encrypt=False;TrustServerCertificate=False;ApplicationIntent=ReadWrite;MultiSubnetFailover=False"))
{
using(SqlCommand cmd = new SqlCommand(SQL, conn))
{
cmd.Connection.Open();
}
}
I have never tried to use databases this way, so maybe I'm doing something wrong. What I'm trying to accomplish, is a way of storing a lot af data temporarily in my app and make it searchable and editable.
EDIT:
I've followed this guide: https://learn.microsoft.com/en-us/visualstudio/data-tools/create-a-sql-database-by-using-a-designer
Thanks in advance

Microsoft Access list all database

I need to fetch all databases of Microsoft Access in localhost.
On clicking the database name I have to list the tables
I can able to fetch the tables for a particular database.
My problem is I cant able to list out the MS Access databases available in localhost
please suggest me the ideas to start coding
I tried
OleDbConnection con; // create connection
OleDbCommand com; // create command
OleDbDataReader dr; //Data read for read data from database
con = new OleDbConnection("Provider = Microsoft.Jet.OLEDB.4.0; Data Source =D:\mydb.mdb");
com = new OleDbCommand("Select * from Table1",con);
con.Open(); // open the connection dr = com.ExecuteReader();
expected result:
with out mentioning Data Source =D:\mydb.mdb" i have to list all ms access databases of
localhost
All available databases like
database1.accdb
database2.accdb
Access (or Jet, to use the name of the database engine) doesn't run a server, in the way that Sql Server or MySql do. An Access database is simply a file of particular format that is loaded on request, but the Jet engine libraries.
For this reason, there's no simple way to find all databases on a local machine: you would need to scan all files on the machine for .accdb or .mdb extensions. More likely, you should ask the user to select a specific file or scan a specified subfolder, since searching the whole machine will likely take a prohibitively long time.

Connecting to SQL Server database with Mono C#

I am trying to migrate my service cross-platform with mono, but in attempting to connect to a SQL Server database I get the following timeout error
Timeout expired. The timeout period elapsed prior to the completion of the operation or the server is not responding. at Mono.Data.Tds.Protocol.TdsComm..ctor
at System.Data.SqlClient.SqlConnection.Open()
Databases are fairly new to me, but as far as I can tell from here (Google cache page, mono site is down) accessing SQL Server databases is now possible in Mono. Is that correct?
I attempted to structure my connection string as shown, but still no luck. My simple test code...
using (SqlConnection con = new SqlConnection(cs))
{
con.Open();
SqlDataReader reader = null;
SqlCommand cmd = new SqlCommand("SELECT Parameter FROM Deltas", con);
reader = cmd.ExecuteReader();
reader.Read();
Console.WriteLine(reader["Parameter"].ToString());
con.Close();
}
Am I missing any references or is my format incorrect? How can I connect using Mono C#?
EDIT:
Connection String, Defined globally and init in constuctor:
cs = #"Server=xxx.xxx.xxx.xxx;
Database=myDB;
User ID=user;
Password=passwd;";
cs = #"Data Source=xxx.xxx.xxx.xxx;
Network Library=DBMSSOCN;
Initial Catalog=myDB;
User ID=user;
Password=passwd;";
Top is me trying to conform to the mono example, bottom is what works with the .NET runtime.
It seems you hit a bug:
http://www.mail-archive.com/mono-bugs#lists.ximian.com/msg50686.html
quote:
This only happens when using the .NET 2.0 version of TdsComm - when
compiling with .NET 1.0 (mcs instead of gmcs), the connection also
works.

INSERT from ASP.NET to MS Access

We are trying to build a Help Desk ticketing system just for intranet. Deciding upon the ASP .NET (C#) with Visual Studio 2008 Express (think we have a full version floating around if we need it). Nothing fancy, couple of pages grabbing NTLM information, system information and storing it along with their problem in a database. Goal is to make it simple, but instead of using our SQL Server 2000 back end, the admin wants me to use MS Access. I have the GridView and connections running smooth. Can pull select queries until my heart is content. However, tying in a couple variables with a text box on a submit button into say an INSERT statement.. well I don't even know where to begin with MS Access. Every internet example is in VB .NET plus seems to be hand coding what Visual Studio has already done for me in a few clicks.
Is MS Access going to be too hard for all we want to do? If not, where do we begin to simply submit this data into the tables?
Edit: After a bunch of playing around we have the OleDB working. It's not pretty, yes SQL Server would be awesome but, sometimes you just have to play ball.
Edit: Anyone looking for an actual coded answer, here you are. There has got to be others out there in the same boat.
string userIP = Request.UserHostAddress.ToString();
string userDNS = Request.UserHostName.ToString();
string duser = Request.ServerVariables["LOGON_USER"]; //NTLM Domain\Username
string computer = System.Environment.MachineName.ToString(); //Computer Name
string connectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\\helpdesk.MDB;";
OleDbConnection conn = new OleDbConnection(connectionString);
conn.Open();
OleDbCommand cmd = new OleDbCommand();
cmd.Connection = conn;
cmd.CommandText = "INSERT INTO ticketing ([user], [comp], [issue]) VALUES (#duser, #computer, #col3)";
cmd.Parameters.Add("#duser", OleDbType.VarChar).Value = duser;
cmd.Parameters.Add("#computer", OleDbType.VarChar).Value = computer;
cmd.Parameters.Add("#col3", OleDbType.LongVarChar).Value = TextBox1.Text;
cmd.ExecuteNonQuery();
conn.Close();
The admin is nuts. Access is an in-process database, and as such is not well suited for web sites where users will be creating or updating records.
But as far as creating INSERT queries go, Access is no harder than anything else. If you can't create INSERT queries for Access you'll probably have trouble with SQL Server as well.
I also suggest using SQL Server, but considering your problem:
What is your problem writing an INSERT query for Access ?
You should make use of the classes that you'll find in the System.Data.OleDb namespace:
OleDbConnection
OleDbCommand
Quick'n dirty code (not compiled whatsoever):
OleDbConnection conn = new OleDbConnection (connectionString);
OleDbCommand command = new OleDbCommand();
command.Connection = conn;
command.CommandText= "INSERT INTO myTable (col1, col2) VALUES (#p_col1, #p_col2)";
command.Parameters.Add ("#p_col1", OleDbType.String).Value = textBox1.Text;
...
command.ExecuteNonQUery();
There are some caveats with the OleDb classes however (like adding the Parameters to the collection in the order that they occur in your SQL statement, for instance).
Don't bother with Access. Use SQL Server Express. There's also an admin tool for it that looks like the full blown SQL Server management tool.
Access has its place, and can usually do more than what most people give it credit for, but yes you want to use SQL Server in ones of its many forms (eg. SQL Server Express) or another proper "server" database for a web app like this.

Categories