简体   繁体   English

如何使我的连接字符串在 C# 中通用,也就是如何使它对我的应用程序的每个用户都可用?

[英]How to make my Connection string universal in C#, aka how to make it usable for every user of my app?

Ok, so i am doing my final project for high school in C#.好的,所以我正在 C# 做我高中的最后一个项目。 I had to include database for best grade.我必须包括数据库以获得最佳成绩。 My proffesor says she can't start my program because she can't read my database file on her PC.我的教授说她无法启动我的程序,因为她无法在她的 PC 上读取我的数据库文件。 I know that my connection string is using my pc info instead of hers.我知道我的连接字符串使用的是我的电脑信息而不是她的。 So how do i make that connection string usable on her PC too?那么如何使该连接字符串也可以在她的 PC 上使用呢? Picture of my Connection string.我的连接字符串的图片。 I just want my app to be usable for every PC where it is started on.我只希望我的应用程序可用于启动它的每台 PC。

Here is my connection string if you can't view picture: Provider=Microsoft.ACE.OLEDB.12.0;Data Source="C:\Users\matij\Desktop\Maturski rad\Maturski rad\bin\Debug\NormaBaza.accdb"如果您无法查看图片,这是我的连接字符串:Provider=Microsoft.ACE.OLEDB.12.0;Data Source="C:\Users\matij\Desktop\Maturski rad\Maturski rad\bin\Debug\NormaBaza.accdb"

Use Environment.SpecialFolder Enum instead of hard coded paths.使用Environment.SpecialFolder Enum而不是硬编码路径。

Something like this:像这样的东西:

var localAppData = Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData);
connection.ConnectionString = $"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=\"{localAppdata}\MyAppName\MyDb.accdb\"";

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何编写外部连接字符串配置文件并使我的C#应用​​程序识别并读取它? - How do I write an external connection string config file and make my c# application recognize and read it? 如果用户在我的 C# 程序中打印“x”,我如何让控制台应用程序退出? - How can i make the console app Exit if the user prints 'x' in my C# program? 如何创建非绝对连接字符串,以便我的小型数据库可以与已发布的C#应用​​程序一起使用? - How do I make a non absolute connection string so my small database works with my published C# application? 如何为我的 c# 应用程序创建链接重定向 - How to make a link redirect for my c# app 如何为我的 C# 应用程序制作安装程序? - How to make an installer for my C# application? C#如何使一个很长的浮点数组可用 - c# how to make a very long float array usable 如何制作一个 ASP.NET C# 电子邮件应用程序供用户从我的网站发送反馈? - How do I make an ASP.NET C# email app for user's to send feedback from my website? 如何让我的 C# 程序在每次完成后从顶部重新启动 - How do I make my C# program start again from the top after every time it finishes 如何在我的C#XAML Windows 8.1应用程序中使我的TextBlocks成为正确的大小? - How do I make my TextBlocks be the correct sizes in my C# XAML Windows 8.1 app? 如果连接丢失,如何使我的Windows桌面c#应用程序重新连接到服务器 - How to make my windows desktop c# application re-connect to the server in case if the connection lost
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM