wcf service can't update a dbf file - "read only" error - wcf

I have a wcf 4 service that is trying to add a record to a visual fox pro dbf file on the same server. When it tries to do the insert I get "Cannot update the cursor USER, since it is read-only."
I assume that this is a permissions problem. What do I have to do to give permission to the wcf service to update my dbf file?
This works on my develpment machine.
Here is some of the code:
OleDbConnection oConn = new OleDbConnection("provider=vfpoledb;Data Source="\\data\\tt.dbc");
oConn.Open();
OleDbCommand oCommand = new OleDbCommand();
oCommand.Connection = oConn;
oCommand.CommandText = "SET NULL OFF\r\nSET DELETED ON";
oCommand.ExecuteNonQuery();
OleDbCommand mycmd = new OleDbCommand("insert into user (lastname,firstname) values ('Doe','John')", oConn);
mycmd.CommandType = CommandType.Text;
lnRet = mycmd.ExecuteNonQuery();

It's not a permissions problem - that would generate an access denied error.
Two things to check:
Is the file marked as read-only?
Is the file being used by any other process?
I think #2 is more likely - I haven't done FoxPro, but I've done a lot of dBase with Clipper, and at least under dBase the file has to be opened exclusively (i.e., not shared) to do inserts/updates/deletions.

You need to verify that the credentials that are used to run the WCF service have Read/Write access to the data UNC path.

Related

Cannot restore database as file is being used by another process

I have developed this application for a store owner.I want to allow the owner to backup and restore database by using the application.the backup runs fine but the restore is causing an exception which says that - Operating system error 32( the process cannot access the file because it is being used by another process).Restore database is terminated abnormally.
using(var conn = new SqlConnection(ConnectionString))
{
using(SqlCommand cmd = conn.CreateCommand())
{
string datadirectory = Path.Combine(Environment.CurrentDirectory,#"Data");
string query = #"RESTORE DATABASE""{0}""FROM DISK= '{1}' WITH REPLACE";
string query = String.Format(query,backupfile,datadirectory + "\\Database.mdf");
conn.Open();
SqlCommand command = new SqlCommand(query,conn);
command.ExecuteNonQuery();
}
}
How can I solve this issue ? Thanks in advance.
You have to dispose of every SQLiteConnection, SQLiteCommand and SQLiteDataReader once you are done using it. The second command that you create isn't correctly being disposed off.
That aside, your code sample doesn't really make sense. You create a command that is never used. Then you create a second command that isn't properly disposed off.
Is it the restore-file that is blocking? Or is the database itself still running?
If it is the database that is being used, you can set the database in single-user-mode. Another option is taking the database temporarily offline and bring it online again. That should close all existing connections. Tip; with SSMS you can turn almost every command into an SQL script like the button to brink a database offline. Click on 'Script' and you get something like 'USE MASTER GO ALTER DATABASE [AdventureWorks] SET OFFLINE GO'.
wait, this is good news. it looks like the application is running, the db is online and live, so why do want to restore? backups are something you do daily/hourly... but restores you ONLY do if something goes wrong. of course you got an error. the db is live and sql service is using the files and it's good it didn't let you restore or else you would have lost a lot of data.
if all you want is to test the restore, then you need to shut down the sql service first.BUT, make sure you take a backup just before that so you restore the latest.

Trouble establishing connection to Local SQL database

Simply trying to find out the correct syntax for my connection string. Before anyone asks, yes I did look at other SO answers, and no they did not work for me. Here a couple of attempts I made from looking at other SO questions like the one I am asking
Server=(local);Database=SalesOrdersExample;Integrated Security= true
Data Source=(local);Database=SalesOrdersExample;Integrated Security=SSPI
Server=.\\SQLEXPRESS;Database=SalesOrdersExampleDataSet;Integrated Security=true
None of them worked (I have a Console.WriteLine("test"); thrown in there and it works up until I try conn.Open() (opening the connection to database) so I'm assuming that it must be my connection string since nothing gets written after conn.Open())
Console.WriteLine("test"); // works
SqlConnection conn = new SqlConnection("Server=.\\SQLEXPRESS;Database=SalesOrdersExampleDataSet;Integrated Security=true");
Console.WriteLine("test"); // works
conn.Open();
Console.WriteLine("test"); // does not work
So some information about the database is that it's local under my 'Data Connections' in my Server Explorer. I also have the .xsd file in my project so I have linked the Data Set to the current project I am on. Here is a picture representation to confirm that I have both the Data Connection and the Data Set.
EDIT: SO does not allow me to post pictures until I have 10 rep so here is direct link to picture:
DB Screenshot
Any help is appreciated thank you.
Visual Studio comes with LocalDB database, which is not exactly SQL Server Express database.
Try something like this:
Server=(localdb)\v11.0;Integrated Security=true;
or
Data Source=(LocalDB)\v11.0; AttachDbFileName=|DataDirectory|\DatabaseFileName.mdf; InitialCatalog=DatabaseName;Integrated Security=True;MultipleActiveResultSets=True
If using in c# code, you can use # to avoid problems with backslash characters:
SqlConnection conn =
new SqlConnection(#"Server=(localdb)\v11.0;Integrated Security=true;");

How can I change my connectionString in app.config file at runtime?

I created my vb.net project to .exe file.
During installation on another machine, one can change the location of installing package to any drive.
In my project, I have set my app.config to point the Database that is available in c:\project.
If I suppose, while installation, when I change the location of installation to **d:** or anywhere, I get invalid access db.
What I want is:
I want to reconfigure my app.config file automatically, by detecting its current db location.
Imports System.Configuration
Imports System.Configuration.ConfigurationManager
Dim config As System.Configuration.Configuration = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None)
config.ConnectionStrings.ConnectionStrings("MyProject.Properties.Settings.MyProjectConString").ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;DataSource=|DataDirectory|\SampleDB;Persist Security Info=True;"
config.Save(ConfigurationSaveMode.Modified)
Where MyProject.Properties.Settings.MyProjectConString is the name of your project and connection string.
Although this is too late to answer as the question is very old but I think this might help someone else in the future.
So, there is a way to change the Connection String value in the runtime. Since connection string is a read-only item like all other items that are on Application Scope under My.Settings so we can't change it using My.Setting.ConnectionString = "Something". But here is the code by which you can solve the issue and change any My.Settings item that is on Application Scope in the runtime.
So the code is,
My.Settings.Item("ConnectionString") = "Something"
simple...
MsgBox(My.Settings.Item("remoteAddress").ToString)
My.Settings.Item("remoteAddress") = "abcserver.servebbs.net"
My.Settings.Save()
MsgBox(My.Settings.Item("remoteAddress").ToString)
You have three options:
1.) Create and use a folder in C:\Databse and set your connection string at design time.
2.)Add the database to the project's data source at design time, then use '|Data Directory|\mydb.mdb' as your connection string.
3.) And if you use sqlserver, you don't need to worry about the location of the database once you have attached the database to sqlserver. You only need to use the proper connection string eg 'Data Source=.; Database = mydb; Integrated Security = False; Username=myusername; Password = mypassword; User Instance = false'.
The above is an example of a sql server with SQL Authentication mode as login, if you use Windows Authentication, set Integrated Security = True and remove both username and password.

How to open the .db paradox file

i want to view the test.db file, i search for it's editor but didn't get any one
So please help to see the it in editor as like sql server.
i found some sqlite editor but it's not an sqlite file on most forum it say that it is an paradox .db file.
So how do i open it
Thanks
To access Paradox tables in .NET you can use ODBC. Here's a small example (in C#):
private static void RunMinimumParadoxTest()
{
const string ConnectionStringFormat =
"Driver={{Microsoft Paradox Driver (*.db )}};Uid={0};UserCommitSync=Yes;Threads=3;SafeTransactions=0;" +
"ParadoxUserName={0};ParadoxNetStyle=4.x;ParadoxNetPath={1};PageTimeout=5;MaxScanRows=8;" +
"MaxBufferSize=65535;DriverID=538;Fil=Paradox 7.X;DefaultDir={2};Dbq={2};CollatingSequence={3}";
DbProviderFactory factory = DbProviderFactories.GetFactory("System.Data.Odbc");
using (DbConnection connection = factory.CreateConnection())
{
string userName = "Tor";
string paradoxNetPath = #"C:\BdeNet";
string databasePath = #"C:\LangloMainSrv\LData\Ordre\LordWin\Database2011";
string collatingSequence = "Norwegian-Danish";
connection.ConnectionString =
String.Format(ConnectionStringFormat, userName, paradoxNetPath, databasePath, collatingSequence);
connection.Open();
using (DbCommand command = connection.CreateCommand())
{
command.CommandText = "select Count(*) from [OrdreDet] where [Ordrenr] = 81699002";
object itemCount = command.ExecuteScalar();
Console.WriteLine("Order items: {0}", itemCount);
Console.ReadKey();
}
}
}
Also see the following link for more details: http://msdn.microsoft.com/en-us/library/ms710922(VS.85).aspx.
A Paradox db file contains just one flat table. The actual structure of the DB file changed over time and different versions. But you can usually open the DB file with MS Excel - of course that changed over different versions too.
As noted above, other database applications, also including Paradox for Dos and Paradox for Windows, will open the file and other features as well. The key, for example is in the PX file with the same table name.
All of this assumes the table is not password protected, which an application database could be - or that you know the password. Beware if you get an error to that effect.
You can open and view Paradox database files using Database Desktop that is shipped with Borland C++Builder. A free alternative is BB's Database Desktop. The software may require administrator privileges to run correctly.
You can use gnumeric spreadsheet, paradox-db-reader or BB database desktop to read db paradox file.
BB database dekstop able to read XG0 file too.
BB's Database Desktop now called JEDI Database Desktop, but project is closed and it couldn't edit my table. I have had to use some hack: open *.db file in MS Excel 2007, edit it, export to *.csv, close file then Open *.db file in Paradox Data Editor 3.2.0, clear all table data and import previosly saved csv-file. And it works (don't know why but this app can't insert row in my file itself)!

SQL Server 2008 Instance connection issue

My problem is the following:
I installes SQL Server 2008 R2 on my Windows Server 2008. I tried it by using default instance name (MSSQLSERVER) and named instance. The Installation was successful without an error. The problem is now:
When I try to connect to my SQL Server with the Management Studio it can't connect to this instance when I write "SERVER1\MSSQLSERVER" as serveraddress. When I write "SERVER1" only in the serveradress field it works.
Note: I always try to connect as SA. The password is right. Dont know if that matters...
But I have to be able to connect to "SERVER1\MSSQLSERVER" because I always get errors when I want to connect to a server without instance by C#.
Can someone tell me where I am mistaking?
EDIT:
The C# code looks like this:
sqlConnection = "data source=(local);persist security info=True;User ID=sa;Password=12345;initial catalog=BBKat"
SqlConnection sqlCon = new SqlConnection( sqlConnection );
SqlCommand sqlCmd = new SqlCommand( sqlCmdString, sqlCon );
I think you are not mistaken at all. You do not write the default instance name while connecting. You can create aliases though as mentioned above.
Try with a single (local) in the server name. and the same in C# web config connectionString as Data Source=(local);Initial Catalog=YOUR_DB;Integrated Security=True
EDIT
Change the connection string as:
data source=(local);Integrated Security=False;User ID=sa;Password=12345;initial catalog=BBKat