Home » Windows OS

SQL CE 3.5 Connection String

After some stumbling I have my MFC & Managed C++ apps talking just fine.

I've found that for installation reasons, the database is going to be in a read-only location.  At first I thought that would be no problem, but I can't see to get this working. 

Here's my connection string:

m_sFileName = "Provider=Microsoft.SQLSERVER.CE.OLEDB.3.5;Data Source='";
m_sFileName.append( "'D:\\projects\\thdb.sdf';" );
m_sFileName.append( "Mode=Read;");
m_sFileName.append( "Temp File Directory='D:\\';" );

When I do this I get the following error:

"Multiple-step OLE DB operation generated errors. Check each OLE DB status value, if available. No work was done."

If I remove the last line and have:
m_sFileName = "Provider=Microsoft.SQLSERVER.CE.OLEDB.3.5;Data Source='";
m_sFileName.append( "'D:\\projects\\thdb.sdf';" );
m_sFileName.append( "Mode=Read;");

I get the following error:
Opening a database as read-only requires a temp path to be specified. [,,,Db name,,]

This leads me to believe there's something wrong with my "Temp File Directory" syntax, but that's how I've found countless samples.

Any assistance would be greatly appreciated.  :)


6 Answers Found


Answer 1

When the database  is on a read-only  location, you must specify a temporary files directory  on a read/write location. This is required for the engine to create temporary files needed when executing queries or doing other bookkeeping.

Answer 2


Thanks for the prompt reply.

Yes, I get that it needs the temp location  for the temp  files, what seems to be eluding me is the syntax  for the temp file  location.

m_sFileName = "Provider=Microsoft.SQLSERVER.CE.OLEDB.3.5;Data Source='"
m_sFileName.append( "'D:\\projects\\thdb.sdf';" ); 
m_sFileName.append( "Mode=Read;"); 
m_sFileName.append( "Temp File Directory='D:\\';" ); 

That gives me the following exception:

"Multiple-step OLE DB operation  generated errors. Check each OLE DB status  value, if available. No work  was done."

In this case, I DO have read/write permissions to the D:\ directory, just the thdb.sdf file itself is marked as read-only  and why I am trying to figure out what is wrong  with my "Temp File directory  = 'D:\\';" to cause the exception.

Thanks again.

Answer 3

Is that directory  writable from your process? According to the BOL, the syntax  should be: "ssce: temp  file directory".

Answer 4


I appreciate all your assistance.

I have tried that with the following:

m_sFileName = "Provider=Microsoft.SQLSERVER.CE.OLEDB.3.5;Data Source='"
m_sFileName.append( "D:\\projects\\thdb.sdf';" ); 
m_sFileName.append( "Mode=Read;"); 
m_sFileName.append( "ssce: temp file directory=D:\\Test\\;" ); 

found  the following MSDN page:

and have also tried:
m_sFileName = "Provider=Microsoft.SQLSERVER.CE.OLEDB.3.5;Data Source='"
m_sFileName.append( "D:\\projects\\thdb.sdf';" ); 
m_sFileName.append( "Mode=Read;"); 
m_sFileName.append( "temp path=D:\\Test;" ); 

To triple make sure I can write to the directory  I even added:
FILE* fp = fopen( "D:\\test\\test.txt", "wt" ); 
fclose( fp ); 

I am just stumped as to why it fails.
- The directory exists
- The process can write to the directory

Regardless I get the "Multiple-Step OLE DB operation  generated errors.

This is on Vista, using the 3.5 SP1 framework, with sql  CE 3.5 with the sdf  file marked as read-only.

Thanks again for any advice.


Answer 5


    One issue could be that there is no space between "SSCE:" and "temp" above. The connection  string option is, "SSCE:Temp File Directory". 

    Also, managed  ADO .NET provider of Compact, does not use OLE DB to talk to the database, so, provider keyword should not be set in the connection string. Since you are using managed C++, it could be that the provider keyword is causing related issues. (Could you please try removing it once, for the connection)? I am not very sure of the thing that managed C++ app uses managed provider (ADO .NET) or not, though, but you can try once.


Answer 6


use the same engine of sqlceme35.dll and sqlce that you use




Hi everybody!

I 'm new to this "synch world" and the question i have is (at least how i think) something easy: is it possible to synchronize two SQL CE databases (one on a windows mobile device and one on desktop PC)? I didn' t find (at least in my understanding) anything which could answer this question.

I 've seen all this tutorials describing the use of a central SQL Server, but this is something i cannot use.

Actually i don't care if the synchronization process is initiated on the mobile device or on the desktop (or should i care??).


If there is someone who can point me in the direction of how to accomplish this task ... i would be grateful.


Thanks in advance


Hi I am trying to use the Lookup transformation to lookup values from a SQL CE database. The problem is that the OleDB data source doesnt have a SQL CE provider. Is there any place to download the SQL CE provider for OLEDB or any alternative way to query data from SQL CE database.

Any help would be highly appreciated. Thanks,




I'm writing a desktop application that uses SQL CE 3.5 to store its data. The .sdf-file is created in %APPDATA% which may be redirected to a network share.

My application opens multiple connections to the database und the second one fails with "file share violation".

I know this is not supported in SQL CE 3.5.


Now I've upgraded to SQL CE 4.0 CTP2 which seems to support multiple connections to a .sdf-file on a network share.

The problem is that my application may be started multiple times, and if a connection to the shared .sdf-file is made from the second process, again a "file share violation" is thrown just as in 3.5.


Does this mean the scenario "multiple connections from multiple processes to a .sdf-file on network share" is still unsupported?





I am facing a strange issue. I am using Entity model to connect to SQL azure DB from my cloud service.

I have configured same connection string for 1 web role and 1 worker role. I have also put the connection string in app.config of the DAL application.

For Worker role the DAL call is executed successfully however it is failing for Web Role.

Error is :

 The supplied connection string is not valid, because it contains insufficient mapping or metadata information.
Parameter name: connectionString

Inner Exception : Unable to determine application context. The ASP.NET application path could not be resolved.



I am trying to deploy a simple windows application to a test computer (not my development computer). I am usinf a SQL compact .sdf database file in my solution. When I publish the solution and install it on the test computer I get this error "the path is not valid check the directory for the database" and it shows me that the connection string is what is was set to this whole time while I built the app which is : 

C:\Users\Eamon\Desktop\VT versions\Vendor Tracker 2.0\VendorTracker 2.0\Database1.sdf"


I've tried changing the connection string to exactly where it would be on the test computer but I still get the error. Am I overlooking something? How to a take the .sdf databse that I put in my windows application, along when I deploy my app to another computer? Confused.



Hi,  I am currently testing a migration from SQL 2000 to SQL 2005.  We have a test server running SQL Server 2005, and production server running SQL 2000.

I currently use some excel VBA to query the database to update or retrieve data.  I do this on my PC at my desk, with SQL server being on a separate server.  The SQL 2000 connection string looks like this:

conn1.Open "Driver={SQL Server};Network=DBMSSOCN;server=xxx.xx.x.x; database=mydb"
We don't specify a uid and pwd as it uses windows authentication.
This same string works when I connect to the SQL Server 2005 database.

I would like to utilize SQL Native Client (wondering if there would be a performance increase) by using the string:

conn1.Open "Driver={SQL Native Client};Network=DBMSSOCN;server=xxx.xx.x.x; database=mydb".  This gives me the error  "Log-in failed for user ''.  The user is not associated with a trusted SQL Server connection.

My next option was to create a SQL user id, call it ACil, and then use the string
conn1.Open "Driver={SQL Native Client};Network=DBMSSOCN;server=xxx.xx.x.x; database=mydb; uid=ACil; pwd=hello". 
This gives me the error  "Login failed for user ACil.  Reason:  The password for this account must be changed".

I assigned the name as db_owner, tried defaulting to different databases for the user, creating another new user, but I always get is this error.  Does anyone know what could be causing it?


I am trying to have a form that displays for the user to enter their own database connection into at the start of the program rather than it all having to be done behind the scenes.

The code I have at the moment is not working, can anyone please help me?!

My.Settings code:


Imports System.Data.SqlClient



    'This class allows you to handle specific events on the settings class:

    ' The SettingChanging event is raised before a setting's value is changed.

    ' The PropertyChanged event is raised after a setting's value is changed.

    ' The SettingsLoaded event is raised after the setting values are loaded.

    ' The SettingsSaving event is raised before the setting values are saved.

    PartialFriend NotInheritableClass MySettings


        PrivateSub MySettings_SettingsLoaded(ByVal sender AsObject, ByVal e As System.Configuration.SettingsLoadedEventArgs) HandlesMe.SettingsLoaded


            'set the variable ConnectionString

            Dim SQLRegKey As String = GetSetting("MusicLibrary", "Settings", "SQLConnectionString")


                If SQLRegKey = ""Then

                    'if the registry key is blank or does not exist make one using a form


                    'retrieve the newly created strring

                    Dim ConnectionString AsString = GetSetting("MusicLibrary", "Settings", "SQLConnectionString")

                    'open the connection string

                    Dim conn As NewSqlConnection()

                    conn.ConnectionString = ConnectionString



                    'retrieve the key from the registry and load the SQL connection

                    Dim ConnectionString AsString = GetSetting("MusicLibrary", "Settings", "SQLConnectionString")

                    Dim conn As NewSqlConnection()

                    conn.ConnectionString = ConnectionString



            Catch ex AsException









Then create a form:


Then the code for this:




    PrivateSub tbServerName_GotFocus(ByVal sender AsObject, ByVal e As System.EventArgs) Handles tbServerName.GotFocus

        'select all the text in the text box and change the back colour


        Me.tbServerName.BackColor = Color.NavajoWhite



    PrivateSub tbServerName_LostFocus(ByVal sender AsObject, ByVal e As System.EventArgs) Handles tbServerName.LostFocus

        'trim the text and change the back colour, populate the built string text box

        Me.tbServerName.BackColor = Color.White

        Me.tbServerName.Text = Trim(StrConv(Me.tbServerName.Text, vbLowerCase))

        Me.tbBuiltConnectionString.Text = "data source=" & Me.tbServerName.Text



    PrivateSub tbInstanceName_GotFocus(ByVal sender AsObject, ByVal e As System.EventArgs) Handles tbInstanceName.GotFocus

        'select all the text in the text box and change the back colour

        Me.tbServerName.Enabled = False

        Me.tbInstanceName.BackColor = Color.NavajoWhite




    PrivateSub tbInstanceName_LostFocus(ByVal sender AsObject, ByVal e As System.EventArgs) Handles tbInstanceName.LostFocus

        'trim the text and change the back colour, populate the built string text box

        Me.tbInstanceName.BackColor = Color.White

        Me.tbInstanceName.Text = Trim(StrConv(Me.tbInstanceName.Text, vbUpperCase))

        Me.tbBuiltConnectionString.Text = Me.tbBuiltConnectionString.Text & "\" & Me.tbInstanceName.Text



    PrivateSub tbDatabaseName_GotFocus(ByVal sender AsObject, ByVal e As System.EventArgs) Handles tbDatabaseName.GotFocus

        'change the back colour

        Me.tbInstanceName.Enabled = False

        Me.tbDatabaseName.BackColor = Color.NavajoWhite



    PrivateSub tbDatabaseName_LostFocus(ByVal sender AsObject, ByVal e As System.EventArgs) Handles tbDatabaseName.LostFocus

        IfMe.tbDatabaseName.Text = ""Then

            'try again

            MsgBox("You cannot leave this field blank.", vbOKOnly + vbCritical, "Music Library")



            'trim the text and change the back colour, populate the built string text box

            Me.tbDatabaseName.BackColor = Color.White

            Me.tbDatabaseName.Text = Trim(StrConv(Me.tbDatabaseName.Text, vbLowerCase))

            Me.tbBuiltConnectionString.Text = Me.tbBuiltConnectionString.Text & ";Initial Catalog=" & Me.tbDatabaseName.Text & ";"




    PrivateSub cbIntegratedSecurity_GotFocus(ByVal sender AsObject, ByVal e As System.EventArgs) Handles cbIntegratedSecurity.GotFocus

        'change the back colour

        Me.cbIntegratedSecurity.BackColor = Color.NavajoWhite



    PrivateSub cbIntegratedSecurity_LostFocus(ByVal sender AsObject, ByVal e As System.EventArgs) Handles cbIntegratedSecurity.LostFocus

        'trim the text and change the back colour, populate the built string text box

        Me.cbIntegratedSecurity.BackColor = Color.White

        Me.tbBuiltConnectionString.Text = Me.tbBuiltConnectionString.Text & "Integrated Security =" & Me.cbIntegratedSecurity.Text



    PrivateSub btnSaveString_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSaveString.Click

        'save the built string to the registry and exit the form

        Dim BuiltConnectionString AsString = Me.tbBuiltConnectionString.Text

        SaveSetting("MusicLibrary", "Settings", "SQLConnectionString", BuiltConnectionString)

        MsgBox("SQL Connection string settings saved.", vbOKOnly + vbInformation, "Music Library")





    PrivateSub btnResetForm_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnResetForm.Click

        'reset the forms properties to blank

        Me.tbServerName.Text = "localhost"

        Me.tbInstanceName.Text = "SQLEXPRESS"

        Me.tbDatabaseName.Text = ""

        Me.cbIntegratedSecurity.Text = "True"

        Me.tbBuiltConnectionString.Text = ""





    PrivateSub btnClose_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnClose.Click

        'close and dispose the form





Thank You




I am having an issue creating a connection string to a remote server. I have Sql Server 2008 installed, Remote connections are enabled, TCP/IP is also enabled. I have tested connecting via Sql Server Management Studio to the remote server and it connects fine, so I am sure that it is allowing connections.

In my app.config file of my Windows Form Application I have the following connection String:

<connectionStrings><addname="WindowsFormsApplication1.Properties.Settings.AccountingConnectionString"connectionString=";Network Library=DBMSSOCN;Data Source=tcp:**.***.*.**,1433;Initial Catalog=Account;User ID =***;Password=***********;Encrypt=yes;Trusted_Connection=False"providerName="System.Data.SqlClient"/></connectionStrings>

If I go to add a datasource to a Drop Down List, I click Add Project Source --> Select Database--> Click Next --> Select Dataset --> Click Next --> Select my connectionString(Settings) and click next. When I do I get the following Error:

Failed to open a connection to the database

"A network-related or instance-specific error occurred while establishing a connection to SQL Server. THe server was not found or was not accessible. Verify that the instance name is correct and that SQL Server is configured to allow remote connections. (provider:TCP Provider, error:0 - The requested name is valid, but not data of the requested type was found.)"

Check the connection and try again.

the only thing I noticed was that I did not have the DBMSSOCN.DLL file in my windows/system32 folder. I downloaded it and put it in there but it didnt help.

Does anyone have any idea if it is because something might be wrong with my connection string or something else?




Hello all.

I'm trying to connect an ASP.NET web form I built in VS2008 to a SQL 2008 server and having nothing but difficulty.  I am in no way an ASP.net programmer and would know how to do this in PHP but I'm completely lost and appearantly there's a billion different ways to accomplish this task.

What i'm trying to do is have this web form I built dump all fields from the form to a DB I created on submit.  Pretty simple but i'm clueless in ASP.  Can anyone point me in the right direction for a simple configuration script or DB connector string which I can use for something like this?


I am having problems getting my VS C# .NET application to connect to a SQL Server Database, even though I can connect to it (on the same machine) using SQL Server Management Studio.

Is there any way I can find the connection string that SQL Server Management Studio generates when it connects?

OK, I have done all of the obvious:
I have MANUALLY copied and installed the cab files on the CE device (the right ones for my processor and version)
I have unchecked the option to deploy the latest versions with my application because they are already there.

The app is using CF 2, SQL CE 3.5 SP1 and SDF 2.3 on Windows CE 5 ARM processor machine.

I am using VS 2008 SP1 (might have been a mistake to upgrade)

When I try to run the app or deploy it tries to copy and install the SQL CE CAB files all the time every time.

Where does it keep the list of files to deploy?

I actually looked at al the files in the project directory and NONE of them refer to the CABS.

ANY HELP would be appreciated.


Hello all,


I have an application running in the .NET Compact Framework 3.5 using SQL CE 3.5 on Windows CE 5.0. I am having a problem where my database is becoming corrupted. To fix this, I have to open it using SQL Server Management Studio 2008 and choose to repair the file.


I would like to figure out how to prevent this from happening so I thought I would try to enable logging. Does anyone know if this is possible and how to do it?





Can anyone give me an example of the proper connection string for getting VS 2010 to use the aspnet database on my SQL 2008 server?  The db is there, I just can't seem to get connected.  Server name GUNSITESQL, mixed security.  I want to logon with a SQL user logon id, the db name is the default aspnet. 


Currently, the web.config file is the default.  Thanks in advance!!


Cory Trapp

Gunsite Academy, Inc.


Hi all.

I have a solution which uses Linq to SQL Data Classes to acced the db. I have a project for my domain objects in my solution, which is a class library and has the dbml file. When I set up the dmbl using the wizard, Visual Studio created an app.config file on that project with the connection string. It also creatting a settings file with the same info. I've noticed that if I change the connection string in the settings file, the app.config gets updated, which is the expected behaviour.

However, I'm having a problem when I deploy my web site to the production server. I already set the app.config file's Build Action to "Content", and also set Copy to ouput directory to "Always". Nevertheless, when I install the web site and change the connection string in the app.config file, it still takes the old connection string, so obviously I get an error. I've found that it only works if I change it with in Visual Studio and then compile, but of course that's not an optimal solution, because any change in the production db server would mean I have to change my project's assembly, thus generating a new version.

Any thing I'm missing? What do I have to configure so that the assembly takes the connection string form my app.config file directly after I deploy?

Thanks a lot.


HI everyone,

I am currently working on a project and I am hosting it on my IIS to test it every so often but now i have an issue:

When i run in debug mode with this connection string:

Data Source=.;AttachDbFilename=c:\New folder\dbname.mdf;Database=dbname;Trusted_Connection=Yes;

everything works fine and i can access the database but once its published onto my iis it doesnt find the database?

Can someone please help?


Hi Guys,

I am experiencing the same problem as described above: "an error occurred while creating the new datasource".  I have followed the above suggestions and have the same dev platform i.e. VS2008 Professional with SP1 installed.

I am not sure if my problem is a little different.  I am able to create a Windows application with a SQL CE database connection and create a dataset referencing the SQL CE database.  If however I create a Windows CE smartdevice application (.NET Framework 3.5) I am still able to create the SQL CE database and open and edit it.  The error is thrown when I try to create a dataset...

I create a connection string to the database (local project folder).  Select the tables I want in the dataset.  When I click FINISH I get this error.  In the project error list the following error is displayed: Error 1 Custom tool error: Failed to generate code. Object reference not set to an instance of an object. 

Are you actually able to create a dataset for a SQL CE database on Windows CE 5.0??  If you are can someone tell me where I should start looking for the problem?

Many thanks




May  be it's a wrong place to ask the following question. Sorry for that. Our hosting provider has recently upgraded their database server from Sql Server 2005 to 2008 and I'm getting errors to connect with remote server from my development machine. Error Message "Invalid connection". Tried to find solution on net but couldn't find it.

I'm using .Net 1.1. Though we've updated versions 2.0,3.5 & 4.0 but due to some certain circumstances I've no way to update it. It's a web based project. The following connection string works fine for Sql Server 2000 & 2005 but not for 2008.

<add key="ConnectionString" value="Data Source=Remote Server's domain name;Initial Catalog=database name;User ID=user name;Password=surround;Persist Security Info=True;Pooling=false;Connect Timeout=45;" />


Remote Server's domain name indicates to remote db server like: test.mysite4now.com

database name for example: test_surround

user name like test_surround

password: surround.

Can anyone inform me what's wrong with the above connection string to connect to Sql Server 2008.





In my program, I want to make database connectivity, but when i write a connection string, complier says that it is unrecognized escape sequence(which is bolded in the following string), the string is :

Data Source=HIMANSHU\SQLEXPRESS;Initial Catalog=Himanshu;Integrated Security=True

How can I resolve my problem?



Hello All, I would appreciate any help with this.

I believe my problem exists within the web.config which already had code in it to connect to SQL Server Express 2008.

I uninstalled the SQL Server Express that came with Visual Studio 2010.

I installed SQL Server 2010 R2 Developer, and I'm able to connect via Management Studio and through Visual Studio's Server Explorer's Data Connections I am connected.

I did run aspnet_regsql.exe within the 4.0 folder in order to create the database with Microsoft Service Providers.

Here is the ServerName: USER-5529234649 

Here is the name of the DataBase:  StepByStepChapter9

Here is the name of the Connection within Visual Studio's Server Explorer's Data Connections:  user-5529234649.StepByStepChapter9.dbo

Here is the code I changed in the web.config:

<connectionstrings><addname="ApplicationServices"connectionString="data source=.\StepByStepChapter9;Initial Catalog=StepByStepChapter9;User ID=sa;Password=ninja71;"providerName="System.Data.SqlClient"/></connectionstrings>

When I attempt to run the Website Administration Tool then Providers then to test AspNetSqlProvider, I receive the following error:

"Could not establish a connection to the database.
If you have not yet created the SQL Server database, exit the Web Site Administration tool, use the aspnet_regsql command-line utility to create and configure the database, and then return to this tool to set the provider"

Can someone please help me with this connectionstring so that it points to SQL Server 2008 R2?


We attempted to implement the Chapter 2 Framework from the Knight, Vermeen, Moss, Hackney book on SSIS 2008: Problem Design Solution. We see a couple of problem areas (at least) in our interpretation of the guidelines from the book.

1. We are attempting to have one connection string per server: dev/prod

2. We have set up environmental variables per server: dev/prod

3. We have set up XML Package Variables per server: dev/prod

4. We have set up System Variables per server in SQL Server: dev/prod

Problem 1:

We've had to manually key in the common connection string to all packages on a server environment in the component properties area (control flow; not data flow--ok there)

Shouldn't the connection property find the connection that we've instantiated and provide us with a pull down to select it?

The components are un-editable after we select the common connection string, but they still run properly in our SQL Server Agent Job.

Problem 2:

The dev server variable overlays the prod server variable information duringprod component editing

We are'nt sure if these problems are related.

Here is our package variable:



Here is our DTSconfig file; we have a few variations of this that we've tried.

<?xml version="1.0"?>
   GeneratedBy="MEDC\SSIS Team"
   GeneratedDate="9/20/2010 04:00:00 PM"/>
  <ConfiguredValue>Data Source=MEDC-SSIS\SSISSQL2008;User ID=sa;Initial Catalog=MedcDwProd;Provider=SQLNCLI10.1;Integrated Security=SSPI;Auto Translate=False;</ConfiguredValue>

I've validated the SSIS_Configurations table for data similarities in both dev and prod.

dev has:

CommonConfigurations Data Source=MEDC-SCCM-SQL\SCCMSQL2008;User ID=sa;Initial Catalog=MedcDwDev;Provider=SQLNCLI10.1;Integrated Security=SSPI; \Package.Variables[User::connMedcDwDev].Properties[Value] String

Prod has 2, since I've been experimenting with the SSIS_MEDC piece.

CommonConfigurations SSIS_MEDC \Package.Connections[SSIS_MEDC].Properties[Name] String    ***(Experimental)

CommonConfigurations Data Source=MEDC-SSIS\SSISSQL2008;User ID=sa;Initial Catalog=MedcDwProd;Provider=SQLNCLI10.1;Integrated Security=SSPI; \Package.Variables[User::connMedcDwProd].Properties[Value] String

Our goal is to make one change per server for the connection strings.

Some of this work was manually performed.

Anyone want to take a critical look at our framework?

Many Regardx,








<< Previous      Next >>

Microsoft   |   Windows   |   Visual Studio   |   Sharepoint   |   Azure