views:

37

answers:

4

Hi friends ,

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 ???

A: 

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

KBoek
nope .. it doenst work out ...it points to some directory . I am tetsing it in desktop ,later stage willmove to server
ITion
A: 

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 Cooray
+1  A: 

See my reply here: http://stackoverflow.com/questions/3223359

ErikEJ
A: 

Hi friends ,

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
ITion