c#,sql和.sdf文件的问题 [英] problem with c#, sql and .sdf file

查看:152
本文介绍了c#,sql和.sdf文件的问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用c#构建软件并存储和读取SQL文件中的数据。

数据库文件以sdf结尾。

我有视觉工作室2012.

我看到答案说要使用:使用System.Data.SqlServerCe; 但是当我编写它时,visual studio会给我一个错误。

我使用visual studio使用本地数据库创建了数据库。

数据库的名称是db-magma,我把它放在项目主文件夹的DB文件夹中。 />
该软件属于我添加的第三行。

有人可以告诉我在 SqlConnection()命令上写什么。

I am trying to build a software using c# and storing and reading the data from an SQL file.
The database file ends with sdf.
I have visual studio 2012.
I have seen answers saying to use: using System.Data.SqlServerCe; but the visual studio gives me an error when I write it.
I created the database using the visual studio using local-database.
The database' name is db-magma and I placed it in a DB folder in the main folder of the project.
The software falls on the third row I added.
Can someone please tell me what to write on the SqlConnection() command.

SqlConnection conn = null;
conn = new SqlConnection("Data Source= DB\\db-magma;integrated security=SSPI;");
conn.Open();

推荐答案

SDF文件不是SQL - 并且SQL无法使用它们,所以没有可以编写的SqlConnection字符串可以使用。您需要使用SqlCe来访问该文件 - 编写它的问题几乎可以肯定到您放置它的位置:在项目主文件夹的DB文件夹中 - 这意味着在生产中它位于程序下文件或程序文件x86,这两者都需要特殊的写入权限。为什么?因为尝试写入与程序相关的ffoldeers越来越多地被认为是类似病毒的可用性的证据,并且强烈建议不要这样做。



将文件移动到普通数据文件夹 - 这应该有所帮助:我应该在哪里存储我的数据? [< a href =http://www.codeproject.com/Tips/370232/Where-should-I-store-my-datatarget =_ blanktitle =New Window> ^ ] - 和您的用户应该有权读取和写入文件。
SDF files are not SQL - and SQL cannot work with them, so there is no SqlConnection string you can write which will work. You need to use SqlCe to access the file - and the problem with writing it is almost certainly down to where you put it: "in a DB folder in the main folder of the project" - that means that in production it is under "Program Files" or "Program Files x86", both of which will require special permission to write to. Why? Because attempts to write to program related ffoldeers is increasingly considered to be evidence of virus-like avctivity and is strongly discouraged.

Move the file to a "normal" data folder - this should help: Where should I store my data?[^] - and your user should have permission to read and write the file.


这篇关于c#,sql和.sdf文件的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆