Connecting to a server with multiple sets of credentials - c#

I'm developing a C# application that needs to connect to a file share (using a service-level account) to download images.
The problem I'm encountering is that the users already have a set of credentials on that share's server that they use for other shares. It's like if you have a share mapped to a drive, you can't log into another share on the same server with different credentials. So when I try and log on with separate credentials for this app's share, I get:
"error 1219: Multiple connections to a server or shared resource by the same user, using more than one user name, are not allowed. Disconnect all previous connections to the server or shared resource and try again."
The code I'm using to try and connect to the share from this example, it uses the WNetUseConnection function.
Any ideas? Thanks.
edit: I've found a workaround for this, I just connect with the host IP address instead of the host name.

Make sure you are disconnecting the user once they are done, otherwise it is crowding the server and it can't allow same user anymore. Restart the server and close all connection after each usage.

Related

Windows-Service fails on net.tcp connection but console app works fine

I built a service that imports and processes data from SQL server and inputs it into SYSPRO. Everything was working perfectly on both local machine and server as a console application. When I made the console application into a service it works perfect on my machine after giving it the proper logins. When I first put the service onto the server, it was giving me a DNS Error when I try to log into a SYSPRO client, even with the proper logins.
private SYSPROWCFServicesPrimitiveClient eNetSession =
new SYSPROWCFServicesPrimitiveClient("net.tcp://{serverName}:20000/SYSPROWCFService/Soap",
SYSPROWCFBinding.NetTcp);
I changed the server name to localhost, its address and local address which no longer returned a DNS error, but would not initialize the SYSPRO client. Yet it has no issue with the SQL Server which is on a different server. I think its the connection string, but not sure what I'm doing wrong as the connection string works just fine on the server as a console application. My only other guess is that the service doesn't have access to net.tcp maybe. Any thought?
UPDATE
Looks like the DNS is set up properly as I can ping the other server and itself. The same connection string is being used on both console and server and the only error message I get back from the service is in the image below.
Sounds like a security context thing. Check the account that the windows service is configured to use (Local System, Network Service, etc). Try changing the account to the user that's running the console application.
Console applications by default run using the account of the logged in user. Windows services on the other hand will need to be configured properly since it does not install with the current user credentials.
To check...
Click Start->Run->services.msc
Look at the column "Log On As"... if it's different from the user that's logged in to the station, change it to that account.

Interop.OpcAutomation.dll not able to connect to Remote Opc server. Error : Access Denied

I am trying to connect remote OPC server from client using C#. I got Interop.OpcAutomation.dll from OPC foundation and it worked very nicely with local opc server, but when comes to connect remote opc server it somehow shows Access denied (HRESULT: 0x80070005 (E_ACCESSDENIED)).
Here is code:
this._reqServer = new OPCServer();
this._reqServer.Connect("OPC.SimaticNET.1", "MachineName"); //Here it throws exception
So here what I already tried:
Configured the permission in DCOM in MyComputerProperties and OPCEnum.
I checked with third party clients such as OpcQuickClient and it can able to access the remote opc server from the same client, which forces me to come to the conclusion that configuration at server side is OK.
So anyone has tried to make some C# client which can access remote opc server, Please tell what more needs to done??
Create a local user on your computer that has the same user name and password as the one on the server. Right click on visual studio and do a run as using that user.
+1 for ambassallo's answer. I have two servers (Win Server 2016 servers) on two different connected networks. One server is on a domain and the other is stand-alone. I have an OPC-DA connection set up between them. The only way to get them to connect (after setting all DCOM, OPCEnum, etc and dropping the firewalls is to log into both machines as the same Windows user (local user on each server) and then connecting the client to the server.
My way is to grant access to the server to a local group, create a user on the server side and define this user as a member of the local group I created. After I create the same user in the client machine with the same password I use in the server side. Adjust ALL DCOM permissions, reboot and try tô connect. Don't forget, do not use NAT anywhere.

How can I redirect URLs entered in the browser?

I want to redirect URLs entered in the browser. For example, when I enter http://microsoft.com, it would redirect to http://127.0.0.1:5000/webpage.html and show this page. I want to do this for all websites entered in the browser.
I don't want to do it by ASP.NET.
I have 10 computers in a workgroup network. I want to manage them by a system that it is server.
My program has 2 client and server versions. Client versions install on PC Clients.
I want to be able to get the client bandwidth systems, And if the bandwidth is over, I redirect browser to a page or port (127.0.0.1:32500) and I stop communicating with internet for all programs on PC Clients. I know that I use proxy, but how?
If I set proxy for browser, other programs can connect to Internet without cross through the proxies.
I want to make a program like net support schools that I can control internet on client (Web access in net support).
I would do this by creating entries in the Windows HOSTS file (C:\Windows\System32\Drivers\etc\hosts).
This is a permanent redirect until the hosts files is changed again.
Also, please be aware that Windows maintains a DNS cache, so if you use something like this, you may have to tell windows to flush it's DNS cache. That can be done by using the command:
C:> ipconfig /flushdns
if you have 10 computer,
1-it's better you put a server like one of them and on the server start dns server like 192.168.1.1 and manage all site and ip you want and for clients set dns on you dns server.
2-it's easier, but if your network bigger you can't administer that. You must open every client hosts file (C:\Windows\System32\Drivers\etc) and add row like
127.0.0.1:32500 microsoft.com
if you want change this file you must run as administrator.

C# with MySQL connector - access denied

I have a remote hosted website with a MySQL database.
I am trying to access that database from a small C# program.
What I've tried:
Referencing the MySQL DLL in the project
Using MySQL connection strings
Disabling my firewall
Adding my IP address to the Remote MySQL Databases in the site's cPanel
What I'm getting:
Access denied for user blabla#mycomputerip in the Visual Studio console
What boggles my mind:
How can I find out if my webhosting service allows remote connections to the DB?
Do I really need to connect with PuTTy to the server and tweak the configs?
^ if so, do I even have access to do that?
LATER EDIT:
Interesting enough. If I do
GRANT ALL PRIVILEGES ON *.* TO 'myuser'#'%' WITH GRANT OPTION;
it throws me this:
#1045 - Access denied for user 'blabla'#'localhost' (using password: YES)
Common sense should tell you that my username is not actually 'blabla'.
LATER LATER EDIT:
I don't have privileges to CREATE USER, nor do I have SSH access via PuTTy or so.
Does this basically mean that it's my hosting's fault that I can't connect from a remote location to the DB?
Have a look at the users in your mysql database. A couple things to check:
With cPanel on shared hosting, if you create a user named blah the actual name of the user in mysql is often unixusername_blah. This is done automatically to prevent MySQL user name conflicts between different cPanel accounts sharing the same MySQL server.
With MySQL you can define which hosts a user is allowed to connect from. Is the new user you defined allowed to connect from your IP?
ETA:
Might want to have a look at the permissions for that user account and make sure appropriate permissions are granted. You can do this by running the following in phpMyAdmin or at the console:
SHOW GRANTS FOR 'something_root'#'localhost'
And compare the grants you see there to what you get here:
SHOW GRANTS FOR 'something_root'#'%'
Finally, depending on your hosting environment you may not have permissions to create new users or expand their privileges enough to be able to do this. This would be particularly likely if you have a shared hosting account.
How can I find out if my webhosting service allows remote connections?
It's better ask your whebhosting proveder, some allows remote connections, other no.
If they allow remote connections you may have to configure which hosts a user is allowed to connect from or, add a wildcard % to allow connections from any host.
Check if your hosting service allows connecting to its database server from outside its network.
Some hosting companies like GoDaddy, by default, don't allow this.
Also, you need to create a database user and assign permissions to it, through your preferred database administration tool.
reset mysql user password and then try again
http://dev.mysql.com/doc/refman/5.1/en/resetting-permissions.html

Access to a windows share through UNC path, before the session opening

I've to do a windows service which starts before the user logon. It's also mean that this service has to do have its own username/password. So how can I open a network share remotly without being logged?
I'm in a windows domain, and the goal is to use some configured credentials to access the remote files I need.
Do you have an idea? I just can't find anything to access easily to the server
Edit: I'm sorry I made a mistake, the client computer isn't in the domain, the server is :(
Generally what you would do is set the service to run under a named user (domain) account and give that user access to the remote share. Then access the files on that share as you would any other i.e.
File.ReadAllText(#"\\SomeMachine\SomeShare\Something.txt");
If you can't run the service as the user in question, you can do it through code with P/Invokes.
Connect to network drive with user name and password

Categories