Click here to Skip to main content
15,892,072 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,

I am writing a connection string as below
cn = New SqlCeConnection([String].Format("Data Source=\Program Files\Compuage\compuage.sdf"))

But i want my compuage.sdf file at the location where my application is installed, not at a particular path.

Can anyone help me

Thanks in advance
Posted

Bad idea: you shouldn't store any data under Program Files, and you shouldn't store data under you app location either. Security policies may prevent you writing to them, if not now, then in future.
Instead, put it in your application data folder:
Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData)
 
Share this answer
 
Comments
Saumyavemula 23-May-11 7:24am    
I mean i want to save my sdf file and exe at the same location
OriginalGriff 23-May-11 7:44am    
And I mean: not a good idea.
Security policy may mean that "normal" access to your application EXE directory could be Execute and / or read: but without write access.
Much better to use a data folder where write permissions will always be available.
Try this. Ensure you have the sqlce server installed first.




Dim conn As SqlCeConnection = Nothing
Dim rdr As SqlCeDataReader = Nothing
Dim connStr As String = "Data Source = C:\myfiles\PPL.sdf; Password ='xxxxxxxxxx'"
conn = New SqlCeConnection(connStr)
Dim cmd As New SqlCeCommand("SELECT * FROM PPL Where CODE='" & Trim(PPID) & "'", conn)
conn.Open()
rdr = cmd.ExecuteResultSet(ResultSetOptions.Updatable)
Try
While rdr.Read()
a = rdr.GetSqlInt64(47).ToString
If Not rdr.IsDBNull(2) Then a = rdr.GetString(2)
End While
Catch ex As Exception
messagebox.show( ex.ToString & vbCrLf)
Finally
rdr.Close()
rdr.Dispose()
conn.Close()
End Try
 
Share this answer
 
Comments
Saumyavemula 23-May-11 7:38am    
Thanks,

But not useful
Karwa_Vivek 23-May-11 7:39am    
Please Use Code Blocks to Post your Codes

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900