March 16, 2012 at 12:09 pm
hi, i am trying to map the network drive using c# script of ssis to l local machine. So please any one help me to figure it out.
March 16, 2012 at 12:13 pm
well the commands to create and delete are like this:
but that's done via a command line...i'm not sure wehterh you'd do that in a script.
I've done it via xp_cmdshell before too.
NET USE Z: \\UNCPath\d$ /user:domain\user password
NET USE Z: /DELETE
Lowell
March 16, 2012 at 12:34 pm
Actually i am trying to map the drive using script in ssis + c#
March 16, 2012 at 1:36 pm
I would actually warn against mapping drives if there is any way to prevent it. It is far better to use UNC paths. In my experieince unless I am trying to use ancient EXEs which can't handle UNC paths I have never had to map a drive.
So why don't you explain what you are trying to accomplish overall instead of just how do I solve problem X.
CEWII
March 19, 2012 at 1:16 am
Elliott Whitlow (3/16/2012)
I would actually warn against mapping drives if there is any way to prevent it. It is far better to use UNC paths. In my experieince unless I am trying to use ancient EXEs which can't handle UNC paths I have never had to map a drive.So why don't you explain what you are trying to accomplish overall instead of just how do I solve problem X.
CEWII
Agreed, but can you pass along credentials with a UNC path?
(the only reason I ever used mapped drives. Only 1 person in the company had access to the folder, so I had to create a mapped drive using that person's credentials)
Need an answer? No, you need a question
My blog at https://sqlkover.com.
MCSE Business Intelligence - Microsoft Data Platform MVP
March 19, 2012 at 10:48 am
True, you can't pass alternate credentials. This is why I would often create a proxy and the process would run in that context.
CEWII
March 22, 2012 at 8:53 am
You can pass credentials when attaching to a UNC
--clear any ipc$ connections
net use \\server\share /delete
--map the drive
net use \\server\share /user:domain\username password
--do whatever you want
--cleanup
net use \\server\share /delete
it can also be done in c# by using net.exe via System.Diagnostics.Process.Start or as a p/invoke via API
March 22, 2012 at 9:41 am
jason_selph (3/22/2012)
You can pass credentials when attaching to a UNC--clear any ipc$ connections
net use \\server\share /delete
--map the drive
net use \\server\share /user:domain\username password
--do whatever you want
--cleanup
net use \\server\share /delete
it can also be done in c# by using net.exe via System.Diagnostics.Process.Start or as a p/invoke via API
Jason you are missing my point, I wasn't talking about using NET USE at all, but a direct reference. However, your reference above would provide the correct security context..
CEWII
March 22, 2012 at 11:06 am
The other alternative along those lines is to impersonate the security context in c# before accessing the network drive, then disposing each time. This would be better if you had different accounts for different shares in the same package as that could not be resolved by a single proxy.
March 22, 2012 at 11:20 am
I generally agree, but what you are trying to do and what technology you are trying to do it from have a big effect here, as well as the availability of xp_cmdshell which is disabled on most of my servers.
CEWII
March 22, 2012 at 11:31 am
True, however the C# route does not use the sql xp command shell (that I know of) so would not be as limiting.
March 22, 2012 at 12:13 pm
True but depending on how you get that C# code called was my point.
CEWII
Viewing 12 posts - 1 through 11 (of 11 total)
You must be logged in to reply to this topic. Login to reply