473,385 Members | 1,782 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Problem using WNetAddConnection2 on 2 different Web Server

Hello there, here my first post ^^

I'm developping a web application that sometimes acces a shared drive not in the Domain with a local machine logon/password.

For that I'm using some code found on the net (WNetAddConnection2A) and it's working pretty well ....

But then I moved my web application to an other server, and now I got a 1312 error (System error 1312 has occurred - - A specified logon session does not exist. It may already have been terminated.)

So basicly I have 2 Web Server in the same domain and one shared folder not in the domaine protected by a local machine account.
It's working perfectly on one of the web server and not on the other. They both have the same security configutation in IIS ...

Some code sample :
Expand|Select|Wrap|Line Numbers
  1. //WIN32API - WNetAddConnection2
  2.         [DllImport("mpr.dll", CharSet = System.Runtime.InteropServices.CharSet.Auto)]
  3.         private static extern int WNetAddConnection2A(
  4.             [MarshalAs(UnmanagedType.LPArray)]
  5.             NETRESOURCE[] lpNetResource
  6.             ,
  7.             [MarshalAs(UnmanagedType.LPStr)]
  8.             string lpPassword
  9.             ,
  10.             [MarshalAs(UnmanagedType.LPStr)]
  11.             string lpUserName
  12.             ,
  13.             int dwFlags
  14.             );
  15.  
  16. public static void ConnectAs(string pShare, string pDomain, string pUser, string pPwd)
  17.         {
  18.             int err = 0;
  19.             try
  20.             {
  21.                 string sUser = string.Empty;
  22.                 if (pDomain.Length < 0)
  23.                     sUser = pDomain + "\\" + pUser;
  24.                 else
  25.                     sUser = pUser;
  26.                 int dwFlags = 0;
  27.                 pShare = GetServerName(pShare);
  28.                 NETRESOURCE[] nr = new NETRESOURCE[1];
  29.                 nr[0].lpRemoteName = pShare;
  30.                 nr[0].lpLocalName = "";  //mLocalName;
  31.                 nr[0].dwType = 1;     //disk
  32.                 //nr[0].dwDisplayType = 0;
  33.                 //nr[0].dwScope = 0;
  34.                 //nr[0].dwUsage = 0;
  35.                 //nr[0].lpComment = "";
  36.                 //nr[0].lpProvider = "";
  37.                 err = WNetAddConnection2A(nr, pPwd, sUser, dwFlags);
  38.                 if (err != 0)
  39.                     throw new Exception("Unable to connect to " + pShare
  40.                         + ".  Error=" + err.ToString());
  41.             }
  42.             catch(Exception ex)
  43.             {
  44.                 throw new Exception("Fatal error : " + ex.ToString());
  45.             }
  46.         }
  47.  
Hope it's clear, thx for your help
May 14 '08 #1
1 3996
kenobewan
4,871 Expert 4TB
I believe that this may happen when the user account exists on one server but not the other. HTH.
May 14 '08 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: quotto | last post by:
I have written a web server application using ASP.Net that handles requests from an HTTP client. I wrote a small test client in VB6 using the MSINet ActiveX control, to load test the server. The...
0
by: Chris Powell | last post by:
Does anyone know if there is an equivalant call or method for the WIN32 API call WNetAddConnection2 to map network drives If not I assume a can import the dll and use it directly ok Thanks,...
0
by: Mirko Parisi | last post by:
Hi all! I have a procedure to Map a Network Drive on Shared Folder from a server in my intranet (this heppens after the user has put Username and Password in a form used for Domain Authentication)...
11
by: Abhishek | last post by:
I have a problem transfering files using sockets from pocket pc(.net compact c#) to desktop(not using .net just mfc and sockets 2 API). The socket communication is not a issue and I am able to...
8
by: nick | last post by:
I have a problem and I've been using a cheezy work around and was wondering if anyone else out there has a better solution. The problem: Let's say I have a web application appA. Locally, I set...
17
by: djmob | last post by:
I am very new to .NET and Windows programming in general so please bare with me... I created a Windows service by deriving a class from ServiceBase and installing it via the 'sc create' ...
1
by: CAIBird | last post by:
Hi, We know that windows API WNetAddConnection2 can make a connection to a network resource. but how to do this job in C#? i'm wondering about it. Thanks -Zhilin
2
by: John M. Gamble | last post by:
I'm getting this message in Visual Studio 2005: PInvokeStackImbalance was detected Message: A call to PInvoke function 'Refresh!Refresh.Main::WNetAddConnection2' has unbalanced the stack. ...
2
by: Sean Peterson | last post by:
Has anyone had success using NetUseAdd() on shares that were replica links on a Windows 2003 DFS root? In my code, I'm getting error: pywintypes.error: (67, 'NetUseAdd', 'The network name cannot...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.