Click here to Skip to main content
13,554,130 members
Rate this:
Please Sign up or sign in to vote.
See more:
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!
Posted 28-Feb-13 0:27am
Steven-Borges 28-Feb-13 6:29am
Atention that I don't want the program to connect to the wireless network, what I want is to place there my IP and go to the folder that has my database file.

1 solution

Rate this: bad
Please Sign up or sign in to vote.

Solution 1

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.
Steven-Borges 28-Feb-13 6:53am
Well I'm very unexperienced when it comes to let other machines connect to a database in my machine, never done it before.
My issue is using the mdf i've created already in SQL-Express and make it public, I have no clue how to do it and what to place on my connection string where once was "."(localhost).

If anyone has the patience to lecture me on that behalf I would be very grateful.
OriginalGriff 28-Feb-13 6:56am
If you already have the database in SQL express then leave it there! All the other PC's need to do is access it via the SQL server instance and database name - the instance will cope with everything else. And SQL server instances are public on your network by default (though you may have to adjust your firewall - I can't tell because I don't know what you are using)
Steven-Borges 28-Feb-13 6:59am
I didn't attach it yet, I have it on a folder and I'm accessing it trough there with the localhost as a connection string.

public static string constr = @"Data Source=.\SQLEXPRESS;
Integrated Security=True;User Instance=True;";

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!
OriginalGriff 28-Feb-13 8:46am
Answer updated.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy |
Web02-2016 | 2.8.180515.1 | Last Updated 28 Feb 2013
Copyright © CodeProject, 1999-2018
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100