我如何在运行时附加数据库 [英] How I attach databse in runtime
问题描述
Hello Guys ...
i想要附上我的Databse(mdf)文件在C#中运行时附加到我的程序...
我怎么能这样做?我有一个数据库,希望用户选择数据库
坦克
我尝试过:
你好家伙...
i想要附上我的数据库(mdf)文件我在C#的Runtime程序中...
我怎么能这样做?我有一个数据库,希望用户选择数据库
坦克
Hello Guys ...
i Want Attach my Databse (mdf) file Attach to my program in Runtime in C#...
how i can Do that ? i have a database and want user select Databse
Tanks
What I have tried:
Hello Guys ...
i Want Attach my Databse (mdf) file Attach to my program in Runtime in C#...
how i can Do that ? i have a database and want user select Databse
Tanks
推荐答案
这里有一些链接可以帮到你开始:
初学者访问指南SQL Server通过C# [ ^ ]
SQL Server DO和DONT [ ^ ]
在连接之前检查Sql Server是否存在 [ ^ ]
Here are some links to get you started:
Beginners guide to accessing SQL Server through C#[^]
SQL Server DO's and DONT's[^]
Check that Sql Server exists prior to connection[^]
全部在连接字符串中:连接字符串中的AttachDBFileName选项 [ ^ ]
但是对于完整SQL(或多用户访问),您应该让SQL处理DB文件本身,并通过Initial Catalog部分再次使用连接字符串:
It's all in the connection string: AttachDBFileName option in Connection String[^]
But for "full" SQL (or multiuser access) you should let SQL handle the DB file itself, and use the connection string again via the Initial Catalog part:
Data Source=DESKTOP-P10HOE9\SQLInstanceName;Initial Catalog=MyDataBaseName;Integrated Security=True
如果要选择用户,可以使用 SqlConnectionStringBuilder.InitialCatalog属性(System.Data.SqlClient) [ ^ ]有一个通用连接字符串并自定义它
If you want user selection, you can use the SqlConnectionStringBuilder.InitialCatalog Property (System.Data.SqlClient)[^] to have a Generic connection string and "customise" it
这篇关于我如何在运行时附加数据库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!