Hi,
I'm developing Pocket Pc application, my application establishes connection with a SQL Server Express 2005 Database. When I try to connect to the database I get an error "SQLexception", when i deploy and run my application both on my physical PDA (HP iPAQ) and the Pocket PC 2003 emulator in Visual Studio 2005. I am working in .Net Compact Framework 2.0 and my PDA runs Windows Mobile 5.0 . Can any one help me to solve this issue?
I use this code:
string connstring = @."Data Source=myserver;Initial Catalog=mydatabase;Integrated Security=SSPI;User ID=uid;Password=pwd";
myconnection = new SqlConnection(connstring);
myconnection.Open();
and this is part of the errormessage:
System.Data.SqlClient.SqlExceptionqlException at System.Data.SqlClient.SqlConnection.OnError() at
When connecting to SQL Server from Compact Framework code using the SqlClient, you should not use the DNS name of the server but rather Data Source = {IPADDRESS}/{SQL INSTANCE NAME} and make sure you have used the SQL SERVER CONFIGURATION TOOLS to enable remote connections and the TCPIP protocol to the running instance of SQL SERVER. So if my machine is 204.21.46.34 and my SQL Express instance is the default (SQLEXPRESS), I'd need to use Data Source = 204.21.46.34/SQLEXPRESS in my connection string.
If that does not resolve your issue, please post the exception details because something else may be going on.
-Darren
|||
You are mixing SQL security and integrated security - remove "Integrated Security=SSPI" from your connection string.
|||Hi Darren,
Unfortunately it didn't solve my problem, here is the complete stacktrace:
at System.Data.SqlClient.SqlConnection.OnError() at System.Data.SqlClient.SqlInternalConnection.OnError() at System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning() at System.Data.SqlClient.TdsParser.Connect() at System.Data.SqlClient.SqlInternalConnection.OpenAndLogin() at System.Data.SqlClient.SqlInternalConnection..ctor() at System.Data.SqlClient.SqlConnection.Open() at DeviceApplication3.Form1.readDatabase() at DeviceApplication3.Form1.btnOpenDB_Click() at System.Windows.Forms.Control.OnClick() at System.Windows.Forms.Button.OnClick() at System.Windows.Forms.ButtonBase.WnProc() at System.Windows.Forms.Control._InternalWnProc() at Microsoft.AGL.Forms.EVL.EnterMainLoop() at System.Windows.Forms.Application.Run() at DeviceApplication3.Program.Main()
/JO
|||I've changed my connection string to
string connstring = @."Data Source=myserver;Initial Catalog=mydatabase;User ID=uid; Password=pwd";
but it didn't solve my problem.
/JO
|||Which error and error message do you get?
|||Hi Erik,
This is the stacktrace;
at System.Data.SqlClient.SqlConnection.OnError() at System.Data.SqlClient.SqlInternalConnection.OnError() at System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning() at System.Data.SqlClient.TdsParser.Connect() at System.Data.SqlClient.SqlInternalConnection.OpenAndLogin() at System.Data.SqlClient.SqlInternalConnection..ctor() at System.Data.SqlClient.SqlConnection.Open() at DeviceApplication3.Form1.readDatabase() at DeviceApplication3.Form1.btnOpenDB_Click() at System.Windows.Forms.Control.OnClick() at System.Windows.Forms.Button.OnClick() at System.Windows.Forms.ButtonBase.WnProc() at System.Windows.Forms.Control._InternalWnProc() at Microsoft.AGL.Forms.EVL.EnterMainLoop() at System.Windows.Forms.Application.Run() at DeviceApplication3.Program.Main()
/JO
|||Yes, but what exception are you getting and what is the error message?|||SqlException has error collection with error messages which you should print out, there's a code sample on MSDN (about one page of code).
But I would guess it would simply tell you it can't establish connection. Please follow this troubleshooting procedure in that case. If you not networking savvy ask your network administrator for help. Also see this.
|||
Hi Erik,
The exception is:
System.Data.SqlClient.SqlException
The error message is:
Specified SQL-server not found.
The SQL-server is my developmentcomputer, I run both the application and SQL-server on the same PC. I can attach and open the database from Server Explorer in VS2005.
/JO
|||The first thing I would do is make sure your instance of SQL Server is configured to accept connections.
Run the SQL Server Configuration Manager (Start->Microsoft SQL Server 2005->Configuration Tools->SQL Server Configuration Manager) and do two things:
1. make sure you understand the exact name of the SQL Server Instance you have installed. In your connection string, you are using MYSERVER and if there is more than one instance of SQL Server -or- you installed with a named instance, MYSERVER as the server name will not work. Again, I encourage you to use the IP address versus the server name when connecting from a device.
2. Open the SQL Server 2005 Network Configuration node and select the instance of SQL Server you are interested in your mobile app connecting to. Go ahead and for now, Enable all of the protocols except for VIA.
Now go back to your mobile device and try to connect. It is confusing to me where your mobile app is running - in an earlier post you indicated it was a Pocket PC app which I assume you have deployed to an actual device connected to your dev machine via ActiveSync. In this last post, you're saying the application is running on your development PC. Maybe we'd better clarify that:
a. this is a Compact Framework 2.0 app
b. you are deploying it to an actual device and then trying to connect via ActiveSync or WiFi. You can open Pocket IE on your device and hit a URL on your dev machine (a great test of the network path between device and server).
c. if you are deploying to an emulator, you have verified that the network connectivity on the emulator is correctly setup to talk to your PC. This usually means enabling the LAN adapter, using Device Emulator Manager to cradle the device, and setting up a proxy on the emulator to allow your Work Network to get to your dev machine.
d. your dev machine running SQL Server has an IP address and network connection as you are testing. If it does not, you need to have the MS Loopback adapter installed and active.
-Darren
|||Sorry Darren;
I really dont want to confuse you, it's enogh me beeing confused.
The application is not running on my development PC it runs on the Pocket PC, what I mean is that i develop the application on a developmentPC and use Active Sync to deploy it on my PPC.
I run SQL Server Express 2005.
this is my coonection string:
connstring = @."Data Source=85.225.253.196\SQLEXPRESS;Initial Catalog=C:\DYNAMICS\APP\CLAMATORVOICESYSTEM\ALARMHISTORY\SQLSERVER\ALARMHISTORY.MDF;Integrated Security=True";
I can ping from my SQL-server to the PPC.
/JO
|||
this helps - the connection string all looks good except I am not sure (which means it's probably an issue) that the mobile version of the SQL Client can handle an Initial Catalog that specifies the attachable DB file. Go ahead and restore your ALARMHISTORY.MDF file into your SQL Express instance (it might already be there) and change the Initial Catalog to ALARMHISTORY.
-Darren
|||darren,
I made the suggested changes and something has haoppend, I now get this error message:
"A native error has occurd in myapplication.exe. Select Quit and restart the program orselect Details for mor information."
This is my connectionstring:
connstring = @."Data Source=85.225.253.196\SQLEXPRESS,;Initial Catalog=ALARMHISTORY;Integrated Security=True";
/JO
|||maybe you must delete the comma after SQLEXPRESS
and add:
;user id=<user>;password=<password>
by the way with these string i can connect to my sql server express:
- after configure network adapter in the pocketpc emulator
- after configure network settings in the windows ce
- after configure properly sql server network protocols
- after configure user in sql server
etc...
No comments:
Post a Comment