开发者

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

开发者 https://www.devze.com 2023-02-02 01:39 出处:网络
I am trying to learn how to program database applications with C#, and I don\'t know very much about it just yet.开发者_开发百科Right now I am trying to develop a very basic database program of my own

I am trying to learn how to program database applications with C#, and I don't know very much about it just yet.开发者_开发百科 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. I've created a database for the program called DakotasContacts, which I made through Visual C# Express. 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. However if I set database to northwind or leave it blank, it'll connect just fine.

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消