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.
Related
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.
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]
I am taking over the maintenance of a website. Virtually no documentation. I hope that this kind of question is "ok" here ...
Right now, I am trying to locate/view the database but I can't find it.
This is the only connectionString in web.config:
<connectionStrings>
<add connectionString="Data Source=YPOC\SQLEXPRESS;Database=Marco;User ID=yyy;Password=xxx;" name="DefaultConnectionString" />
</connectionStrings>
QUESTIONS:
1) are these parameters equivalent?
a) Database=Marco
b) AttachDbFilename=|DataDirectory|\Marco.mdf
c) Initial Catalog=Marco
2) if the answer to #1 is "yes", then I should find a database file called Marco.mdf in the App_Data folder, right?
3) but #2 can't be correct, because I do not see a database file called Marco in the App_Data folder ... ;-x
4) where in the world is carmen sandi ... oops, I mean Marco.mdf ?!
RELATED QUESTIONS:
I had to copy all the files from a production server called YPOC. In the web.config, I think I need to change "Data Source=YPOC\SQLEXPRESS" ... my SQL Server Instance Name is "SQLEXPRESS" ... therefore, should I change the DS to "Data Source=.\SQLEXPRESS"?
In the App_Data folder, I found ASPNETDB.MDF ... in Server Explorer, I try to connect to view the tables, but I get an error message:
"...cannot open because it is version 661. This server supports version 655 and earlier"
I did some research and it appears that version 661 means that it needs SQL Server 2008 R2 ... but I have that installed already ... ;-(
I'm used to a shared hosting environment where the SQL Server DB is set up and it's easy to connect. Here, it is on a dedicated cloud server (unmanaged) and I'm been thrust upon new territory where I can't even find the database ... ;-(
Any help is greatly appreciated ...
nano
Stop, stop, stop, stop, stop using the User Instance and AttachDbFileName nonsense. Please. You will be much more sane if you forget they exist. I'm totally serious. The user instances feature has been deprecated for a reason.
Take your MDF file, which you can find by searching using Windows Explorer (if you've been using this user instance feature, you will probably find multiple, and I have no suggestions for determining which one is the right one). Once you've found the one you want to use, attach it to a proper instance of SQL Server using CREATE DATABASE Marco ... FOR ATTACH_REBUILD_LOG. Your connection string should then point to your server (yes, .\SQLEXPRESS should be fine if you are connecting locally), and should refer to your database by logical name (e.g. Marco, no path information to a specific MDF file).
Also you'll want to install Service Pack 1 for SQL Server 2008 R2. It seems like you created a database in a post-RTM build of SQL Server 2008 R2 (or in 2008 with SP2+).
"But how do I access this database from my dev computer when I don't know the SQL server address, etc?"
I found the Marco database. It is on SQL Server that is located on an unmanaged web server account. The way to access the database is to use a Remote Desktop Connection, then use SQL Server Management Studio that is located on the server (not my dev desktop). The SSMS then found the server/database and voila, connected ... my confusion was in trying to connect using SSMS from my dev desktop directly instead of using SSMS located on the server via RDC ...
I've created an entity model file (.edmx) based on an .mdf file in my asp.net application, placed in my App_Data Folder.
first of all my connection string, created by the entity framework wizard :
<connectionStrings>
<add name="Sales_DBEntities"
connectionString="metadata=res://*/Model1.csdl|res://*/Model1.ssdl|res://*/Model1.msl;provider=System.Data.SqlClient;provider connection string='data source=.\SQLEXPRESS;attachdbfilename="c:\users\ext\documents\visual studio 2010\Projects\WebProject_A\WebProject_A\App_Data\Sales_DB.mdf";integrated security=True;USER INSTANCE=TRUE;multipleactiveresultsets=True;App=EntityFramework'"
providerName="System.Data.EntityClient" />
</connectionStrings>
The above is placed in an app.config file created by the wizard.
I've copied the same connection string to the web.config file as well (I'm not sure if this is necessary).
I've come across two problems when attempting to later run the same application on a my machine (I've created the application on a different machine).
The first was regarding the user instance:
Failed to generate a user instance of SQL Server due to a failure in starting the process for the user instance. The connection will be closed
The first thing I don't really comprehend is what a user instance actually defines.
According to MSDN :
A user instance is a separate instance of the SQL Server Express Database Engine that is generated by a parent instance
Is my local database considered a user instance ?
I would really like some clarification on the matter because I came across posts suggesting
to mark it as False, and the reason was not clear to me .
another post on this matter
From there I came across another solution that explains that for this problem you need to
enable user instance in the SQL Server on your machine.
The Fix
I've done what was explained in that post
but now I've come across a new problem :
An attempt to attach an auto-named database for file (Full Path to my app_data\my.mdf file) A database with the same name exists, or specified file cannot be opened, or it is located on UNC share.
I've already attempted to delete all the files under
C:\Documents and Settings\(your user account name)\Local Settings\Application Data\Microsoft\Microsoft SQL Server Data\SQLEXPRESS
and rebooting like suggested in other posts, but still I can't find a clear solution for this problem.
I know this is a long post but any help would be appreciated
thanks in advance.
Read this very good overview of what user instances really are.
In a nutshell:
SQL Server allows you to have multiple instances of itself on a single computer - the default instance can be accessed using just the machine name (or IP address) of the host machine - all other instances need to be specified by an instance name (like the SQLExpress on your machine)
for development purposes, you can also create a user instance - each user gets their own separate instance of SQL Server (works in the Express edition only) and a database is attached by its file name (path\Sales_DB.mdf) to that user instance. This instance is started up on demand, then runs and is shut down when no longer needed
While this works great for development, it's not really intended for later on - certainly not for production use.
In a production environment, you want to attach your database files to the actual SQL Server instance they should run on - typically using SQL Server Management Studio. When you do this, you no longer refer to that database via its file name, but instead you use the database name that was given to the database when being attached to the server. In this case, SQL Server will handle all details of operations - and that SQL Server instance is up and running all the time (doesn't need to be started "on demand" all the time), and you can use things like permissions and logins to control access to the database.
Your connection string would then look something like this:
<connectionStrings>
<add name="Sales_DBEntities"
connectionString="metadata=res://*/Model1.csdl|res://*/Model1.ssdl|res://*/Model1.msl;provider=System.Data.SqlClient;provider connection string='server=YourServerNameHere;database=Sales_DB;integrated security=True;App=EntityFramework'"
providerName="System.Data.EntityClient" />
</connectionStrings>
When you have attached a database to a production (or testing) SQL Server instance, you do not need to know what the files are that make up the database, and you don't need to specify those files - SQL Server will take care of that. You just refer to the database via its database name.
The solution is always simpler then anticipated:
double click the model.edmx file -> the designer will open.
right click on the designer -> Update model from database .
new connection -> Choose Database file (.mdf) under type .
Browse -> go to your App_Data folder, and choose the DB.
copy the connection string created in App.config to web.config.
bye.
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.