简体   繁体   English

如何将自己的数据库与连接字符串中的(local)\\ netsdk关联?

[英]How do I associate my own database with (local)\netsdk in the connection string?

I am trying to learn how to program database applications with C#, and I don't know very much about it just yet. 我正在尝试学习如何使用C#对数据库应用程序进行编程,而我对此还不是很了解。 Right now I am trying to develop a very basic database program of my own creation (not just copying an example), and I do not want to use SqlDataAdapter or anything else like that - just the basic stuff, for learning purposes. 现在,我正在尝试开发自己创建的非常基本的数据库程序(而不仅仅是复制示例),并且我不想使用SqlDataAdapter或其他类似的东西-只是基本的东西,用于学习目的。 I've created a database for the program called DakotasContacts, which I made through Visual C# Express. 我已经为通过Visual C#Express创建的名为DakotasContacts的程序创建了一个数据库。 Now I'm trying to get the correct connection string. 现在,我试图获取正确的连接字符串。 At present I have: 目前我有:

 static string connectionString = @"
        server = (local)\netsdk;
        database = DakotasContacts;
        integrated security = sspi;
        ";

That doesn't work very well. 那不是很好。 I've also tried setting database to dakotascontacts, with similar results. 我也尝试过将数据库设置为dakotascontacts,结果相似。 However if I set database to northwind or leave it blank, it'll connect just fine. 但是,如果我将数据库设置为Northwind或将其保留为空白,它将正常连接。

How can I get that string to work? 如何使该字符串起作用? Thanks. 谢谢。

SqlConnection con = new SqlConnection(@"Data Source=.\SQLEXPRESS;AttachDbFilename='Path to Database file .mdf';Integrated Security=True;User Instance=True");

for example 例如

SqlConnection con = new SqlConnection(@"Data Source=.\SQLEXPRESS;AttachDbFilename='"+System.IO.Directory.GetCurrentDirectory()+"@\Customer.mdf';Integrated Security=True;User Instance=True");

System.IO.Directory.GetCurrentDirectory() by this u can get the path of the current directory where your program is. 通过此方法,System.IO.Directory.GetCurrentDirectory()可以获取程序所在的当前目录的路径。

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

相关问题 如何将ICacheClient与ServiceStack中的单独数据库关联? - How do I associate my ICacheClient with a separate database in ServiceStack? 我应该在哪里放置我的数据库连接字符串以及如何处理连接池? - Where should I place my database connection string and how do I handle connection pooling? 如何修复 Azure 管道错误.NETSDK1152? - How do I fix Azure pipeline error NETSDK1152? 如何创建非绝对连接字符串,以便我的小型数据库可以与已发布的C#应用​​程序一起使用? - How do I make a non absolute connection string so my small database works with my published C# application? 如何将我的应用程序与 Windows 7 任务栏上的固定程序相关联? - How do I associate my application with a pinned program on the Windows 7 taskbar? 我的连接字符串在其自己生成的连接字符串上出错。 我该如何解决? - My connectionstring is erroring on its own generated connection string. how would i fix this? EntityFramework在哪里获得到本地数据库的连接字符串? - Where does EntityFramework get the connection string to my local database? 如何在azure中为我的Web应用程序设置连接字符串? - how do i set the connection string for my web application in azure? 如何在连接字符串中使用文件路径? - How do I use a filepath in my connection string? 本地.m​​df数据库连接字符串 - local .mdf database connection string
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM