Can't get SQL Connection string with IP address to work

B

Bryan

Hello,
I am using a windows mobile device with pocket PC, for some reason I cannot
get the sql connection string to use IP address instead of machine name. I
can get the IP to work with same connection string on my desktop PC to
server. I am thinking that there must be something different in the
sqlclient for the compact framework.
My connection string that works looks like this:
Data Source=MachineName\SQLEXPRESS;Initial Catalog=MYDB;User
ID=myid;password=mypass

I want to get this to work:

Data Source=192.168.0.15\SQLEXPRESS;Initial Catalog=MYDB;User
ID=myid;password=mypass

Any and all help is greatly appreciated!
Thanks,
Bryan
 
G

Ginny Caughey [MVP]

Bryan,

It works for me on my machine, but I also include the port number as well as
the IP address. You do have tcp/ip enabled for Express, right? It's disabled
by default.

Here's some code:

string hostComputerIP = "169.254.25.129,2301";
//open Connection to SqlExpress using IP address and port
// this example uses SQL Server authentication
string connString = "Data Source=" +
hostComputerIP + ";Initial Catalog=Northwind;user id=sa;password=Password!";
 
B

Bryan

Yes, I had to turn that on to get it to work even with machine name. I tried
the IP address with the port number, it didn't work either.

Thanks for your suggestions!

Any more help out there?

Bryan
 
G

Ginny Caughey [MVP]

Bryan,

The other might be that you can't reach the machine. If you've got IIS
running on your computer, you could try surfing to that ip address.
 
D

Darren Beckley

If it works using a hostname without dots, but doesn't work with dotted
address, I would guess it's a Connection Manager configuration issue.
Connection Manager will by default assume any address with dots in is on
"The Internet". Try changing "Programs that automatically connect to the
Internet should connect using:" to be "My Work Network" i.e. both Internet
and private networks use "My Work Network" settings. You'll find this under
Start -> Settings -> Connections -> Connections -> Advanced -> Select
Networks. Alternatively, you could add an exception for 192.168.* or
similar - see Exceptions button in same place as Select Networks.

Hope that helps,
Darren
 
G

Ginny Caughey [MVP]

Bryan,

Can you connect to that server from the desktop using the IP address?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top