[英]c# winforms GetCurrentDirectory returns C:\WINDOWS\System32\ design error
I'm making like a cashier app with a winforms project and i need to use an access database and i used System.IO.GetCurrentDirectory()
. 我正在制作一个带有winforms项目的收银应用程序,我需要使用访问数据库,并且使用了
System.IO.GetCurrentDirectory()
。 But it returns C:\\WINDOWS\\System32
on design time so it keeps popping up message boxes when i'm using the designer. 但是它在设计时返回
C:\\WINDOWS\\System32
,所以当我使用设计器时它会不断弹出消息框。
It also returns the correct directory when i run it. 当我运行它时,它还会返回正确的目录。
Here's an example of my connection string: 这是我的连接字符串的示例:
OleDbConnection conn = new OleDbConnection();
string dataPath = System.IO.Directory.GetCurrentDirectory();
conn.ConnectionString = @"
Provider=Microsoft.ACE.OLEDB.12.0;
Data Source=" + dataPath + "/Data/Databases/database.accdb;Persist Security Info=False";
Any help will be appriciated. 任何帮助将被申请。
Edit: 编辑:
What happens when i try to open the designer: https://i.stack.imgur.com/HQjHa.png 当我尝试打开设计器时会发生什么: https : //i.stack.imgur.com/HQjHa.png
Not sure why this is happening but u can try : 不知道为什么会这样,但是您可以尝试:
System.Environment.CurrentDirectory
//or
Application.StartupPath
//or
System.IO.Path.GetDirectoryName(Application.ExecutablePath);
//or
System.IO.Path.GetDirectoryName(Assembly.GetEntryAssembly().Location);
//or
System.AppDomain.CurrentDomain.BaseDirectory
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.