I wrote Windows Service in C# to get data from Excel and Access tables. Everything works fine until I try to get data from remote database through VPN connection:
ERROR [HY000] [Microsoft][ODBC Microsoft Access Driver] The Microsoft Access database
engine cannot open or write to the file '(unknown)'. It is already opened exclusively
by another user, or you need permission to view and write its data.
Driver is ODBC.
The answer is in the error message. It's not very helpful but is completely accurate.
It's likely that your service is running as a user that does not have the needed permissions to the file, or that the ODBC connection is supplying the credentials and they are wrong or missing.
You can debug your service by opening the project in Visual Studio and selecting Debug->Attach To Process and selecting your service. You can then step through it and see exactly what is failing and what login credentials are being used when it happens.
Note that the default credentials for Windows Services do not have rights to anything on other machines, so that would be a good place to start.
If you can open it across the VPN from MS Access, but not your service, that narrows it down quite a bit.
Related
I created a VS setup project in which I added a custom action to create an SQL Server database. I used the code from here https://daoudisamir.com/install-sql-server-database-with-visual-studio-setup/ that is itself a c# adaptation of the Microsoft Docs code here: https://learn.microsoft.com/en-us/previous-versions/visualstudio/visual-studio-2010/49b92ztk(v=vs.100). I made a little adaptation - the entire connection string is in the code:
string connStr = "Data Source = (localdb)\\MSSQLLocalDB; Initial Catalog = master; Integrated Security=True";
This way, I'm not using any dialogue during the installation and it starts the custom action without any input from the user.
But when trying to the installation file, I get each time a "Failed to connect to server (localdb)\MSSQLLocalDB" error. Some of the times, the inner exception message that I have in the log file said "Login failed for user 'NT AUTHORITY\SYSTEM'", sometimes just "A network-related or instance-specific error occurred while establishing a connection to SQL Server. The server was not found".
I know for a fact it's not the code in the custom action - I copied it to a form and added a button for the db creation via the application itself - no problem, no connection problem, db created right away.
I must add, that previously, I had a prerequisite for installing SQL Server Local DB during the application setup. That ended up miserably - it blocked me from having ANY access to the server - I had to uninstall everything VS and reinstall again before it went back to normal.
It seems to me that for some reason, instead of using the default windows user that is running the setup file, for some reason it switches to a different user. Is running the code via an msi file causing this? How can I solve it? It's been 2 full days, I read many threads and didn't find the answer.
Thank you for any help.
Edit: The LocalDB documentation states specifically that
An instance of LocalDB owned by the built-in accounts such as NT
AUTHORITY\SYSTEM can have manageability issues due to windows file
system redirection. Instead use a normal windows account as the owner.
HOWEVER, I didn't choose to run under SYSTEM. For some reason it switches to this user, while after the installation when the application is running with the same connection string, it uses the normal Windows user as expected.
Why is it switching to this user? That's what I'm trying to figure out. I have windows 10 if it matters.
I have the following code that I am trying to get working:-
using (AdomdConnection conn = new AdomdConnection(_connString))
{
conn.Open();
Console.WriteLine(conn.ConnectionString);
Console.WriteLine(conn.Cubes.Count);
}
The following error is thrown with and without the conn.Open() line:-
A connection cannot be made to redirector. Ensure that 'SQL Browser' service is running.
I don't have a SQL Browser service available on the client machine I'm using. But what's vexing me is this exact same connection string works from Excel and pulls back a set of OLAP Cube measures which I can pivot as required.
The connection string is as follows:-
Provider=MSOLAP.4;Integrated Security=SSPI;Persist Security Info=True;Initial Catalog=RaptorMarketRiskSummary;Data Source=ssasp-raptor\plnqic01_as;MDX Compatibility=1;Safety Options=2;MDX Missing Member Mode=Error
Does anyone have any ideas?
Many thanks.
Did you try this?
This error seems to related only to named instances. The reason is SQL client is not able to resolve instance because SQL client has no access SQL Browser Service. SQL Browser Service resolves instance name
1.Ensure SQL browser service is running
2.Ensure the port on which SQL browser service runs, is not blocked from PC (default port 2382)
Alternatively, you can bypass SQL Browser Service, by mentioning "Server:Port" instead of "Server\instance name", in the client connection properties
This is an old answer from :
a connection cannot be made to redirector. Ensure that 'sql browser' service is running
Look a the Alternatively point :)
It turns out that this error
A connection cannot be made to redirector. Ensure that 'SQL Browser' service is running
can be caused by problems which have nothing to do with whether the SQL Browser is running or not. (This is intuitively the case given that I could connect from Excel.)
At my workplace each employee has a personal space on a network drive. Because I intended my app to be a quick proof-of-concept to demonstrate .Net's ability to connect to OLAP cubes, I used a folder on my personal network drive as a scratch area. I then tried connecting to another database (directly, not through a cube) and discovered I had a permission issue. I compiled the binary (from Visual Studio) and placed it on another network drive so that a colleague could test from his machine. In checking the binary would throw an error, I ran it from the second network drive and it connected fine and brought back some data.
Changing the app back to connect to my OLAP cube and moving the Visual Studio solution to my local C: drive has resulted in being able to connect to the cube fine and pull back the data I want!
So: the 'Check SQL Browser service is running' error is a catch-all piece of advice which covers a multitude of sins underneath. Permissions can depend on where the app is running from (i.e. which network drive, not just whether the drive is network or local).
Hope this helps :)
I'm having trouble connecting to the MySql database. I googled around, but could not find a solution that worked for me. I have a console app written in c# that works on my localhost. Connects to the database and just works. When I then use this app and run it with Mono, I cannot connect to the database. Thinking it was a permissions issue based on some of my googling, I checked the grants for the user I'm trying to connect with, and it says:
GRANT ALL PRIVILEGES ON *.* TO 'root'#'localhost' IDENTIFIED BY PASSWORD...
(This is me ssh'ing into the machine and checking the grants of its localhost).
So that part is set up correctly. My coworker has another console app that connects to the database, and I just copied and pasted what they did to connect, but for some reason, I'm not able to connect. Other there are other troubleshooting things I should look out for? Thanks.
I have a network with a server and many computers connected to it. I have a software installed on the server which is accessed and used by many clients.
Now i have created a reporting tool using c#/Winforms. In summary it connects to Access DB and creates reports. And each pc on the network contains an Access DB , so we give path to that DB and it creates report for that pc we connect using path like:
\WinPc\Tmuser\Database\users.mdb
When WinPc is the computer name , Tmuser is the shared folder on the pc which contains the database. This works perfectly fine when i have the application (c#/Winform) on the man server it can connect to any pc and generate reports.
But when i put the tool on any pc and give path of Db on another pc it gives error as below:
And i cannot figure out why this error shows up , as when i check the path in explorer it opens the access Db just fine. Kindly let me know if you have any suggestions.
The issue was the permissions, the pc it was connecting too needed credentials when from another pc, instead of server so it did not let it open files... Changing the current user to domain account worked
as the error says, the database is exclusively open by another user.
what i would suggest, because you have a lot of PCs that may try to access the DB is to make a server-client project so every client send requests to write a line to the main server, and the server side in the main server will take those requests and write them to the DB, that way only one computer will write to DB and no one will lock the DB
also, i may not seeing your code, but i'm guessing you forgot to release the DB at some point. always use Using statement when using streams or Connections
I have a console app that needs to connect to a remote sql server 2008 instance....
this particular line throws an error even though i have access to that database...
connection.open() is the line that is throwing the error...
Make sure that Sql server 2008 instance available at your system where you are running your application.
Atleast client version of Sql server 2008 should be installed on development machine.
Check connection string and server system also allow network connection.
Make sure the connection string in you console app uses the same credentials and settings that you use to successfully connect in management studio.
Are you using Windows authentication in one place and a SQL login in another?
Have you been able to connect to this remote server before? If you have been able to connect previously, but cannot do so now, that may be an indication that a backup copy of the database, from another server, has been restored to that server.
When you write that you "have access" to that database, how do you connect? Close your copy of SQL Server Management Studio and re-open it; when you get the Connect dialog, be sure to enter the user credentials that your console app uses to connect. Do you see your database? Are you able to execute stored procedures, run SELECT statements, or otherwise do what you would expect?
If you do not see the database--or if you cannot do the activities you expect, you have probably restored a database from another server. This is very common--a database developer is working on the next revision of the database on his development machine; when it comes time to deploy he backs up the database, copies it to the server, and restores the database. Now he can't connect--and can't understand why.
The reason is that the Login and User are presented in the SSMS UI as strings--but in fact they are integer IDs. You will have to do a bit of scripting to delete the invalid User record from the database in order to assign it to the new server's Login.
If this sounds like your problem, respond--I'll check back in a bit, and follow up with more help.
JM