1

I have done a web project ( using C# + SQL CE + ASP.NET )where it does few manupulation with .sdf file and results are displaye via ASP.net page . While i started working I hardcoded the path of the connection string and worked in my system . Now I want this database to be residing inside my server page.

How do i get the working directory( localhost) so that i can put that in connection string ?

I tried using

System.Environment.CommandLine but it throws me a error saying

"Format of the initialization string does not conform to specification starting at index 98." The outcome of System.Environment.CommandLine is

Data Source= "C:\Program Files\Common Files\Microsoft Shared\DevServer\9.0\WebDev.WebServer.EXE" /port:1438 /path:"C:\Documents and Settings\xxx\Desktop\Project\yyy\Deploy\EMSWEB\Back010\WEB\WEB" /vpath:"/WEB"/tEST.sdf;Persist Security Info=True;

Any idea ???

Verve Innovation
  • 2,006
  • 6
  • 29
  • 48

3 Answers3

0

Have a look at http://www.connectionstrings.com/sql-server-2005-ce

KBoek
  • 5,794
  • 5
  • 32
  • 49
0

Just a quick advise: Never put this in to a real environment. SQL Server CE is NOT to be used as a database to a web application. It does not perform well with concurrent access.

And as @KBoek has said, connectionstrings.com should cover any of your connection string problems. Whether it is Desktop or Server, it is only a matter of specifying the path correctly to the database. I suggest you keep the .sdf file in the same directory as your other files

and use something like

Data Source=" + (System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().GetName().CodeBase) + "\\MyData.sdf;Persist Security Info=False;
Ranhiru Jude Cooray
  • 19,542
  • 20
  • 83
  • 128
0

I finally made it work using

connectionString="data source=|DataDirectory|\test.sdf"

where as

 Data Source=" + (System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().GetName().CodeBase) + "\\

Points to some directory like this below.

C:\Program Files\Common Files\Microsoft Shared\DevServer\9.0\WebDev.WebServer.EXE" /port:1438 /path:"C:\Documents and Settings\xxx\Desktop\Project\yyy\Deploy\EMSWEB\Back010\WEB\WEB" /vpath:"/WEB"/tEST.sdf
Verve Innovation
  • 2,006
  • 6
  • 29
  • 48