[英]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.