IoriYagami80(80后的八神庵) ( ) 信誉:100 Blog 加为好友 2007-04-20 13:39:50 得分: 0
把数据库位置写成网路路径
可以说的详细点吗?不懂你的意思,谢谢了
共享文件/通过Web Service等方式操作数据库
请给个例子吧,没有做过access的远程连接,谢谢了
If you just want to establishes a connection between the local computer and a remote network share, simply use Process.Start to issue a net use command.using System.Diagnostics; .... string device = "X:"; // local device mapping string uncpath = @\\server\share; ProcessStartInfo psi = new ProcessStartInfo(); psi.FileName = "cmd.exe"; psi.Arguments = String.Format("/c net use {0} {1}", device, uncpath); psi.WindowStyle = ProcessWindowStyle.Minimized; Process proc = Process.Start(psi); proc.WaitForExit(); if(proc.ExitCode != 0) .... .....Willy.
Here's how to achieve the same using Management namespace classes.using System; using System.Management;public class Wmis { public static void Main() { string sharename = "TEMP"; UInt32 ret = Create("Test", 10, sharename, "passwordhere", @"c:\tmp"); Console.WriteLine("Creation returned: " + ret); ManagementObject share = new ManagementObject("Win32_Share=" + "'" + sharename +"'"); string s = (string)share.Properties["Description"].Value; // read property "description" Console.ReadLine(); // press enter to delete share ret = Delete(share); Console.WriteLine("Deletion returned: " + ret); } public static UInt32 Create(string Description, UInt32 MaximumAllowed, string Name, string Password, string Path) { ManagementBaseObject inParams = null; ManagementClass classObj = new System.Management.ManagementClass(null, "Win32_Share", null); inParams = classObj.GetMethodParameters("Create"); inParams["Access"] = null; // default Security descriptor used inParams["Description"] = Description; inParams["MaximumAllowed"] = MaximumAllowed; inParams["Name"] = Name; inParams["Password"] = Password; inParams["Path"] = Path; inParams["Type"] = 0; // Disk drive 0, print queue 1 ManagementBaseObject outParams = classObj.InvokeMethod("Create", inParams, null); return Convert.ToUInt32(outParams.Properties["ReturnValue"].Value); }public static UInt32 Delete(ManagementObject share) { ManagementBaseObject inParams = null; ManagementBaseObject outParams = share.InvokeMethod("Delete", inParams, null); return System.Convert.ToUInt32(outParams.Properties["ReturnValue"].Value); } }Willy.
把连接字符串的server设置为服务器IP地址就可以啊
把数据库位置写成网路路径
可以说的详细点吗?不懂你的意思,谢谢了
issue a net use command.using System.Diagnostics;
....
string device = "X:"; // local device mapping
string uncpath = @\\server\share;
ProcessStartInfo psi = new ProcessStartInfo();
psi.FileName = "cmd.exe";
psi.Arguments = String.Format("/c net use {0} {1}", device, uncpath);
psi.WindowStyle = ProcessWindowStyle.Minimized;
Process proc = Process.Start(psi);
proc.WaitForExit();
if(proc.ExitCode != 0)
....
.....Willy.
using System.Management;public class Wmis {
public static void Main() {
string sharename = "TEMP";
UInt32 ret = Create("Test", 10, sharename, "passwordhere", @"c:\tmp");
Console.WriteLine("Creation returned: " + ret);
ManagementObject share = new ManagementObject("Win32_Share=" + "'" + sharename +"'");
string s = (string)share.Properties["Description"].Value; // read property "description"
Console.ReadLine(); // press enter to delete share
ret = Delete(share);
Console.WriteLine("Deletion returned: " + ret);
}
public static UInt32 Create(string Description, UInt32 MaximumAllowed, string Name, string Password, string Path)
{
ManagementBaseObject inParams = null;
ManagementClass classObj = new System.Management.ManagementClass(null, "Win32_Share", null);
inParams = classObj.GetMethodParameters("Create");
inParams["Access"] = null; // default Security descriptor used
inParams["Description"] = Description;
inParams["MaximumAllowed"] = MaximumAllowed;
inParams["Name"] = Name;
inParams["Password"] = Password;
inParams["Path"] = Path;
inParams["Type"] = 0; // Disk drive 0, print queue 1
ManagementBaseObject outParams = classObj.InvokeMethod("Create", inParams, null);
return Convert.ToUInt32(outParams.Properties["ReturnValue"].Value);
}public static UInt32 Delete(ManagementObject share)
{
ManagementBaseObject inParams = null;
ManagementBaseObject outParams = share.InvokeMethod("Delete", inParams, null);
return System.Convert.ToUInt32(outParams.Properties["ReturnValue"].Value);
}
}Willy.