简体   繁体   English

如何连接本地SQL数据库?

[英]How to connect to local SQL database?

As of now I've been given a piece of software that reads XML files and presents these graphically, to give the user some overview to the events these files describe. 截至目前,我已经获得了一个读取XML文件并以图形方式显示这些文件的软件,以便向用户提供这些文件描述的事件的概述。

The crux as of now is that one of the engineers using the software has requested that all the data you load into the program should be possible to save to a database. 截至目前的关键是使用该软件的工程师之一要求您加载到程序中的所有数据都应该可以保存到数据库中。

My pickle is as follows: 我的泡菜如下:

public void addToDBO(List<List<EventElement>> insertList)
{
    SqlConnection s1 = new SqlConnection();
    s1.ConnectionString = filePath;
    s1.Open();
    SqlCommand command = new SqlCommand();
    command.Connection = s1;
    foreach (List<EventElement> item in insertList)
---------------------SNIP----------------------------
//Adding-data-to-database logic

I mean to write the loaded data into a database deployed localy, but the the problem is that it does not accept my hamhanded methods of simply adding the database's filepath as the filepath string. 我的意思是将加载的数据写入部署在localy中的数据库,但问题是它不接受我简单地将数据库的文件路径添加为文件filepath字符串的简化方法。

So, to summarize: How do I correctly connect to a database situated on my C:/? 因此,总结一下:如何正确连接到位于我的C:/上的数据库?

Thank you in advance. 先感谢您。

在此输入图像描述

You do not simply pass a file path. 您不只是传递文件路径。 The connection string needs to follow a certain convention. 连接字符串需要遵循某种约定。 For example 例如

Provider=SQLNCLI10;Server=.\SQLExpress;AttachDbFilename=c:\asd\qwe\mydbfile.mdf;
Database=dbname;Trusted_Connection=Yes;

See http://www.connectionstrings.com/sql-server/ for more 有关更多信息,请访问http://www.connectionstrings.com/sql-server/

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM