Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Find causing "Stream does not support writing" exception #690

Closed
ghost opened this issue Aug 10, 2017 · 21 comments
Closed

Find causing "Stream does not support writing" exception #690

ghost opened this issue Aug 10, 2017 · 21 comments

Comments

@ghost
Copy link

ghost commented Aug 10, 2017

Hi,

Using the following code causes a "Stream does not support writing" exception:

public IEnumerable getCaseByCaseGUID(Guid CaseGUID)
{
using (var db = new LiteDatabase(NoSQLDatabaseReadOnly))
{
var Case = db.GetCollection(NoSQLCollectionName);

            var results = Case.Find(x => x.CaseGUID == CaseGUID);

            return results;
        }
    }

My connection string (NoSQLDatabaseReadOnly) has Mode=ReadOnly in it.

Trying to figure out why a Find call is attempting to write to the database? Is this by design? What are the workarounds?

Thanks.

@mbdavid
Copy link
Owner

mbdavid commented Aug 10, 2017

Hi @testbench, if your collection doesnt contains an index in CaseGUID column, LiteDB try to auto-create this index and if you are readonly mode you get this error.

Try open shared/exclusive mode and create this index.

In next v3.5 version there is no more auto index and in this case, LiteDB will do a full scan search.

@ghost
Copy link
Author

ghost commented Aug 10, 2017

Hi,

thanks for the quick response. I have two issues with this, being:

1 - When set to exclusive mode I get errors with the file being locked by another process
2 - When attempting to set Mode=Shared I get the error "'Invalid connection string value type for [mode]'"

My packages.config contains: package id="LiteDB" version="3.1.2" targetFramework="net452"

@mbdavid
Copy link
Owner

mbdavid commented Aug 10, 2017

Hi,

1- Exclusive mode can be open only one-per-time. Dont forget to always use using statement to compiler call Dispose() method
2- There is no shared option in NetStandard version. You must use net35 version to enable this option.

@ghost
Copy link
Author

ghost commented Aug 10, 2017

Whats the process for using the net35 version?

@ghost
Copy link
Author

ghost commented Aug 10, 2017

do you simply mean having my project target .Net 3.5?

@mbdavid
Copy link
Owner

mbdavid commented Aug 10, 2017

I was reviewing nuget and net451 are the same net35. Downgrade you problem to net451 and get from nuget

@ghost
Copy link
Author

ghost commented Aug 10, 2017

Removed LiteDB, downgraded to 4.5.1 and used nuget to install litedb 3.1.2, same error "'Invalid connection string value type for [mode]'"

@ghost
Copy link
Author

ghost commented Aug 10, 2017

Any ideas?

@ghost
Copy link
Author

ghost commented Aug 10, 2017

Hi @mbdavid

Retargetting to 4.5.1 and reinstalling litedb did not make any difference. Same error. Any other suggestions?

Thanks

@mbdavid
Copy link
Owner

mbdavid commented Aug 11, 2017

Ok, now comparing new .csproj in master branch with dev branch they are different. You must set your project to .NET3.5 to download correct version. I'm fixing this for new 3.5 version

@ghost
Copy link
Author

ghost commented Aug 11, 2017

OK will try this thanks

@ghost
Copy link
Author

ghost commented Aug 12, 2017

@mbdavid I have it running fine with v3.1.1 - when do you expect the new v3.5 to be available?

@mbdavid
Copy link
Owner

mbdavid commented Aug 12, 2017

HI @testbench, I will delivery beta version next week. An them, I will wait community helps me testing and finding bugs (especially about concurrency access).

@ghost
Copy link
Author

ghost commented Aug 12, 2017

Thanks @mbdavid - well done on the project too, it's great!

@a-a-k
Copy link

a-a-k commented Dec 3, 2017

I'm new in LiteDB. So guys, what is the solution? I have db as embedded resource and here is the usage:

        public static void AddUser(long id, string name)
        {
            using (var memory = typeof(DbActions).GetTypeInfo().Assembly.GetManifestResourceStream("HadithBot.UmmahDb.db"))
            {
                using (var db = new LiteDatabase(memory))
                {
                    var table = db.GetCollection<User>("Users");
                    if (!table.Exists(u => u.ChatId == id))
                    {
                        var user = new User()
                        {
                            Name = name,
                            ChatId = id,
                            IsAdmin = false
                        };

                        table.Insert(user);
                        table.EnsureIndex("ChatId", true);
                    }
                }
            }
        }

There I get this error. What is wrong?
I'm work with netcore.

@mbdavid
Copy link
Owner

mbdavid commented Dec 3, 2017

Hi @a-a-k, it's not possible modify embedded assembly resource. Use an external file or in-memory stream

@a-a-k
Copy link

a-a-k commented Dec 4, 2017

@mbdavid thanks for your response. Could you provide any example of usage "in-memory stream"?

@mbdavid
Copy link
Owner

mbdavid commented Dec 4, 2017

You can use MemoryStrem class as your database stream.

var mem = new MemoryStrem();

using(var db = new LiteDatabase(mem))
{
    // ...
}

var databaseInBytes = mem.ToArray();

@a-a-k
Copy link

a-a-k commented Dec 5, 2017

@mbdavid I've saw that at Quickstart page but this usage unclear for me. What is the profit of such way? Will it only runtime data? Please, explain this way or give me link to explanation )

@mbdavid
Copy link
Owner

mbdavid commented Dec 5, 2017

Memory databases are useful for unit test or some in-memory processing, like create a temporary database for sort data using an index. In this thread #805 I made some examples

@lbnascimento
Copy link
Collaborator

Hi! With the objective of organizing our issues, we are closing old unsolved issues. Please check the latest version of LiteDB and open a new issue if your problem/question/suggestion still applies. Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants