shared folder route in ASP.Net, Framework 2.0 - asp.net

I have this problem:
I have a web application that was working ok on accessing shared folder in same server application, but outside of application folder.
The route of shared folder is stored in a table (SQL Server 2008 R2), this is query using sqlcommand and datareader, including credentials to access the shared folder.
Suddenly that part of application stop working, the problem I found is that the path of shared folder appears without the char '\', something like this \IP_SERVERsharedfolder altough in database it is stored as \\IP_SERVER\sharedfolder, if the query is executed on sql server managment, it displays the whole path.
Do you have experienced a similar problem.
I appreciate your help.
The problem here is not how to access the shared folder, that means, the problem is when the path is gotten from database where it is stored, I use a data reader object to get from database:
If dtrReader.HasRows Then
fldPath = dtrReader(3).ToString
username = dtrReader(4).ToString
password = dtrReader(5).ToString
End If
in variable fldPath , I got \IP_SERVERsharedfolder instead \\IP_SERVER\sharedfolder, char \ is removed.

Related

How to configure Permissions: SQLite for ASP.Net Website?

I am trying to use SQLite for my ASP.Net Website.
The code is working fine in a Windows Application, but not in the WebAPP. I think I have to change some File Permissions to let the Website set up a Database. But how?
I always get a ERROR at the open() statement. Saying cannot open file.
Following the Code, which is working fine in the WindowsAPP:
Dim connDB as SQLiteConnection = New SQLiteConnection("PlayerDB.sqlite")
Dim conn = New SQLiteConnection("Data Source=PlayerDB.sqlite;Version=3")
conn.open() ---> ERROR
...
I hope someone can help me quick.
Thanks.
There are two reasons why you can get this error, so you must make sure that both these are taken care of before running your code.
You need to specify the absolute path to the database in your connection string and not a relative path that you are currently using in your code since SQLite database is just a file. For this you need to create a special folder for sqlite databases in your ASP.Net app. Let's say you have created a folder called sqlite under the root folder. Then your code should be as below. Server.MapPath is an utility method in ASP.Net framework to convert a root relative path to an absolute path that looks like c:\abc\wwq\myfile.db.
Dim connDB as SQLiteConnection = New SQLiteConnection(string.Format("Data
Source={0};Version=3;",Server.MapPath("~/sqlite/PlayerDB.sqlite")));
conn.open() ---> NO ERROR should happen now
You should also make sure that the ASP.Net application identity is allowed read/write access to thesqlitefolder created in above step under the root of your web app because data will be read as well as written to the database file under this folder.
Just right click on the sqlite folder and select Properties and then the Security tab as in screen shot below. In most localhost cases, the ASP.Net identity is IIS_IUSRS which is highlighted below. Make sure that this user has full control over the sqlite folder.

I can not access my db

I make a software in C# .net express edition in in windows 7.But When I run this software in other machine in which install windows XP,it can not run due to instance failure.When I set the break point in other machine code,I see that it hold the database location path of my machine.Actually i want to access the db from my debug folder.
Like..
DB Location in may machine -- F:\MY Project\Tracking Soft\bin\debug\TRack.mdf
DB Location In Other Machine -- E:\Tracking Soft\bin\debug\TRack.mdf
I mean that in the both machine the connection string is same but the project location is different
When using SQL Server express, you can put your database file into the App_Data folder (e.g. in CATracking\App_Data). Then you should be able to access it using a connection string like this one:
Server=.\SQLExpress;AttachDbFilename=|DataDirectory|TRack.mdf;Database=...
Try this code
private string dbPath = Application.StartupPath + "\\bpTracking.mdf";
But your bpTracking.mdf isn't in the correct directory. Move it into \bin\Debug for this code to work.

How to add database to setup in c#

I have made a setup for my C# application but when i installed it on another computer, it showed me an error that Path is invalid. I used the following code.
public string Path1 = (#"|DataDirectory|\MakeMyBill.sdf");
SqlCeConnection conn = new SqlCeConnection(Path3);
conn.Open();
if your application is running fine before creating setup and you are just asking the way to include database in setup then-
- I put the database with exe [in bin->debug folder]
- and while creating setup i put the database in Application folder with .exe.
[as you know there are 3 parts in file system -Application folder , user's desktop and user's program menu]

Unable to connect to SQL database in AppData when deployed to web server

I have a ASP.Net program written in C# that uses a database stored in the AppData directory, the program works perfectly on my development (Win7\SQL 2008R2) when I deploy to a Win2008R2\SQl 2008 R2 server the program is unable to connect to the database. I'm using the connection string below. Several sites suggest I set the Application Pool to use 'Network Service' as this has Modify permission to the AppData directory, I have done this but it still won't work, another site suggested I Application Pool to "Load User Profile = True" but still no joy.
I'm pulling my hair out with what else to try, can anyone help?
data source=.\SQLEXPRESS;Integrated
Security=SSPI;AttachDBFilename=|DataDirectory|\DB.mdf;User
Instance=true
I get "Object reference not set to an instance of an object." in my app and "An attempt to attach an auto-named database for file C:\inetpub\wwwroot\ADPhonebook\App_Data\DB.mdf failed. A database with the same name exists, or specified file cannot be opened, or it is located on UNC share." in the Application Event Log
I really appreciate any advice, thanks.
Steven
As Martin points out in the comments, it would be interesting if you posted the exact error message (and maybe the full exception detail) you are getting.
But problems like this have mostly to do with rights at the OS level.
So make sure that the user (identity) of the Application Pool has full access (ntfs) rights to the .mdf file, and try again.
Edit (after you posted the exact message):
Ok, I guess this means that on the server you're deploying to, there is already a database called DB on that Sql Server instance. So you will have to remove or rename that one in order to be able to attach a database with that name.
I think the user rights problem is also still possible though.

Proper way to specify database connection string in a DataSet.xsd

I have a Windows CE Form (NETCF 3.5) application that I've created via Visual Studio 2008 (c#) - (However, the core of my question probably applies to normal Windows application, too).
The application implements a SQLite database that I've placed within the project - i.e. The database location is in the sub-directory within my project. So the connection string to the database looks something like:
#"Data Source = C:\src\myApp\data\mydb.s3db"
The connection to the database is fine and works.
After I created the database, I added a Data Set via VS2008's "Data Source Configuration Wizard" (in VS2008, go to Data > Add New Data Source...). The wizard allows us to create a connection to an existing database and, then, choose tables from within that database that will be used in the Data Set that the wizard is about to create.
So the wizard does a fine job of creating the data set which allows us to program against it. The problem that I have is when I deploy the application to my WinCE device.
The problem that I encounter is when the application attempts to access the database when it needs to fill the Data Set with data.
The root of the problem is, the connection string to the database that is defined in the Data Set is per the dev machine - not the local path per the WinCE device.
For example: The connection string in the Data Set is set to
#"Data Source = C:\src\myApp\data\mydb.s3db"
instead of the full path of the target device similar to
#"Data Source = \Program Files\myApp\data\mydb.s3db"
I was able to fix the problem by manually editing the Data Set's .Designer.cs file (at the InitConnection() method). However, it would be nice if VS2008 can manage the connection string for me somehow - i.e. when in dev mode, the connection string points to the database on my dev machine. When in deploy mode, the connection string points to the database on the device.
Is there a way to specify the connection string to point to a relative path rather than the full path, maybe? Or?
Use "|DataDirectory|" in your connection string.
Quote from http://social.msdn.microsoft.com/Forums/en-US/sqlce/thread/dc31ea59-5718-49b6-9f1f-7039da425296/ ...
|DataDirectory| (enclosed in pipe symbols) is a substitution string that indicates the path to the database. It eliminates the need to hard-code the full path which leads to several problems as the full path to the database could be serialized in different places. DataDirectory also makes it easy to share a project and also to deploy an application.
For example, instead of having the following connection string:
"Data Source= c:\program files\MyApp\Mydb.sdf"
Using DataDirectory, you can have the following connection string:
“Data Source = |DataDirectory|\Mydb.sdf”
To set the DataDirectory property, call the AppDomain.SetData method. If you do not set the DataDirectory property, the following default rules will be applied to access the database folder:
For applications that are put in a folder on the user's computer, the
database folder uses the application folder.
For applications that
are running under ClickOnce, the database folder uses the specific
data folder that is created.

Resources