使用IP地址连接到mdf数据库 [英] Connect to mdf database using an IP-Address

查看:122
本文介绍了使用IP地址连接到mdf数据库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以我主要完成了我的应用程序,我准备在其他计算机上测试它。

问题是我的连接字符串有。对于本地主机而言我并不确切知道应该放在那里。



我想要的是以下内容,我将创建一个无线网络我的电脑上的接入点与所述提示以下代码:

<预郎= 文本> netsh的WLAN集hostednetwork模式=允许SSID = YOURFRIENDLYSSID键= SOMEPASSWORD

netsh wlan启动hostednetwork





这将使我的机器成为服务器,我想让其他机器连接到该无线网络并连接到我桌面文件夹内的.mdf。



就C#的代码而言,我该如何在连接字符串中实现它?

而且我也不知道在ipconfig中使用哪个IP,是不是我的无线适配器?



提前谢谢!

解决方案
如果您在无线网络上运行,然后你,我不会做这种方式。

的第一个原因是,IP地址取决于您的DHCP控制器 - 通常是您的路由器或网络交换机,它们可以通过两种不同的方式配置 - 静态IP和动态。在静态模式下,您的PC将始终接收相同的IP地址,但在动态时,它将在连接时接收下一个可用的IP地址。有可能在动态网络中修复一些地址,但这取决于您的DHCP控制器(Netgear路由器,Belkin通常不会)。



所以如果你稍微改变你的网络,你的系统可能会崩溃而你没有线索的原因!



第二个是有更好的方法 - 使用命名主机并命名股来代替。



。如果您共享文件夹了在Windows PC上,你可以给它命名,并通过PCName /共享名组合连接到和DCHP将为您整理IP地址。所以,如果你的网络改变(或要到数据库移动到不同的PC,因为你是过得去的所有访问猛击),你只需移动份额(和潜在的计算机名称),以在不同的机器,一切都继续工作不变。



但说实话,我也不会这样做。使用多用户时MDF文件不好 - 如果事情发生在错误的时间,它会给出可怕的问题。我建议您将MDF文件附加到SQL Server实例并使用它。







上次我放弃使用SQL-Server Express,因为它没有从我的MDF加载表格和数据,它会加载没有表格的数据库!



嗯 - 我觉得你做错了什么!通过以下方式将DB加载到SQL服务器中:

1)打开Sql server Management studio,并创建一个新的空数据库。

2)右键单击Object中的数据库资源管理器。

3)选择任务|从上下文菜单导入数据....

4)将数据源更改为Microsoft Access。

5)浏览文件名。

6)单击下一步...

7)选择新数据库作为目标。单击下一步

8)确保选中从一个或多个表或视图复制数据,单击下一步

9)在每个表中打勾包括。单击下一步

10)忽略你不能保存此警告。单击Next。

11)按完成,然后在完成时关闭。



您现在拥有完整的表结构,数据作为SQL数据库中。

So I mostly finished my application and I''m ready to test it on other computers.
Problem is that my connection string has the . for the localhost and I don''t know exactly what I should put in there.

What I want is the following, I''m going to create a wireless access point on my computer with the following code on the prompt:

netsh wlan set hostednetwork mode=allow ssid=YOURFRIENDLYSSID key=SOMEPASSWORD 

netsh wlan start hostednetwork



This will make my machine the server, and I want to make the other machines connect to that wireless network and connect to the .mdf that is inside a folder in my desktop.

In terms of code for C#, how should I implement this in the connection string?
And I also don''t know which IP to use in the ipconfig, is it my wireless adapter?

Thanks in advance!

解决方案

If you are operating on a wireless network, then I wouldn''t do it this way.
The first reason is that the IP address will depend on your DHCP controller - normally your router or a network switch and they can be configured in two distinct ways - static IP and dynamic. In static mode, your PC will always receive the same IP address, but in dynamic it will recieve the next available when it ties to connect. It may be possible to fix some addresses in a dynamic network, but that depends on your DHCP controller (Netgear routers do, Belkin generally don''t).

So if you change your network slightly, your system may fall apart without you having a clue why!

The second is that there is a better method - use named hosts and named shares instead.

If you share a folder out on a windows PC, you can assign it a name and connect to that via the PCName/ShareName combo, and the DCHP will sort out the IP addressing for you. So if your network changes (or you want to move the DB to a different PC because yours is getting slugged by all the accesses) you can just move the share (and potentially the pc name) to a different machine and everything continues to work unchanged.

But to be honest I wouldn''t do that either. MDF files are not good when used multiuser - it can give horrible problems if things happen at the wrong time. I would recommend that you attach the MDF file to a SQL Server instance and use that instead.



"Last time I gave up using SQL-Server Express because it didn''t load the tables and data from my MDF, it would load the database with no tables at all!"

Um - I think you did something wrong! Load the DB into SQL server by:
1) Open Sql server Management studio, and create a new, empty database.
2) Right-click the database in the Object Explorer.
3) Select Tasks | Import Data... from the context menu.
4) Change the data source to Microsoft Access.
5) Browse for the file name.
6) Click Next...
7) Select your new database as the destination. Click Next
8) Make sure that "Copy data from one or more tables or views" is selected, click Next
9) Put a tick in each table you want to include. Click Next
10) Ignore the "you can''t save this" warning. Click Next.
11) Press Finish, then Close when complete.

You now have the complete table structure complete with data as an SQL database.


这篇关于使用IP地址连接到mdf数据库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆