views:

237

answers:

1

When I try adding a new data source to my project I get a prompt saying "The connection you selected uses a local data file that is not part of the current project. Would you like to copy the file to your project and modify the connection?"

This sounds rather obscure to me, as I'm new to VB.NET and programming non-script apps in general. The data source in this case is a .sdf SQL CE file.

Question 1: If I say that I want to copy the database to the project, what will happen after I compile the app, where the database will be? (how will I edit it from another app?)

Question 2: If I do not include it, how the data source will still keep linked? Can I link using filesystem enviroiment variables like %ProgramFiles%\MyAppDir?

Question 3: Can I just tell it to use a read-only (Just needs to read it) data source on the web, like on an FTP?

Thanks for help in advance! =)

A: 

Visual Studio just tries to have all your files in one place, with the rest of them - in project folder.

Q1 - SQL Ce database can be anywhere you like, you use ConnectionStrings settings section in your app.settings. SQL Ce is just a file, nothing more, nothing less, therefore accessible from any application. Is is not compiled into your app, it just travels with it when you deploy etc.

To answer Q2 - you probably can, but I'm not sure that it will work automatically for you.

Q3 - to read from ftp, probably not, unless you work ftp client support into your app and download it in background. Another solution would be to map ftp to local drive and access it from there.

For example, storing connection string in app.config (excerpt from app.config):

<connectionStrings>
   <add name="db" connectionString="Provider=Microsoft.SQLSERVER.OLEDB.CE.2.0; data source=c:SomePathToSDFfile" />
</connectionStrings>

Later in your application, you access this connection string like this: (add reference to System.Configuration)

  Dim c As Configuration.ConnectionStringSettingsCollection
  Dim cn As SqlClient.SqlConnection

  c = Configuration.ConfigurationManager.ConnectionStrings
  cn = New SqlClient.SqlConnection
  cn.ConnectionString = c.Item("db").ConnectionString
  cn.Open()
Vnuk
Q1 - but where it has to stay after the app is compiled, in the same dir? (e.g. ".\file.sdf") If i can make that a parameter in something like an .ini file would be ideal. can I?
Camilo Martin
No it doesn't have to be in the same dir. The parameter can be anywhere, even in ini file, registry key, or application configuration, since you specify in your connection string the path to file.
Vnuk
thanks ^^ ticked
Camilo Martin