Connecting to a database on a LAN network location

不问归期 提交于 2019-12-13 01:18:38

问题


I have an application that I want to access a file over a network. I am currently using this connection string.

string myconnectionstring = "Provider=Microsoft.Jet.OLEDB.4.0; Data Source=\\" + PCName + "\\datafolder\\data.mdb";

The Pc name is the name of well the computer as seen on the network I get that using:

Dll Netapi32 however while i do get the path exactly as it should be my code adds "C:" to the path instead of "\PCNAME\datafolder\data.mdb" I have read a lot on this and none of it makes much sense because my code looks exactly as it should except i get that complication.


回答1:


Your code line is looking pretty good. Try to add @ before the string or add back slash like this \\\\" + PCName

string myconnectionstring = "Provider=Microsoft.Jet.OLEDB.4.0; Data Source=\\\\" + PCName + "\\datafolder\\data.mdb";

If still it creates problem then assign that database shared folder as a Mapped Drive and use something like this. for example mapped drive is Z: (\\PCName\ApplicationFolder)

string myconnectionstring = @"Provider=Microsoft.Jet.OLEDB.4.0; Data Source=Z:\datafolder\data.mdb";

also this solution does not working then the problem may be in network pc permission.



来源:https://stackoverflow.com/questions/23489980/connecting-to-a-database-on-a-lan-network-location

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!