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

单DbConnection情境下如何保持一直Open #191

Closed
tky753 opened this issue Jan 20, 2020 · 5 comments
Closed

单DbConnection情境下如何保持一直Open #191

tky753 opened this issue Jan 20, 2020 · 5 comments

Comments

@tky753
Copy link
Contributor

@tky753 tky753 commented Jan 20, 2020

单元测试,用的Sqlite 的 :memory: 模式,单一DbConnection,中途Close()的话是不是会重置?
尝试fSqlBuilder.UseConnectionFactory(DataType.Sqlite, () => connection)这种写法,
但在UnitOfWork Commit 时会调用到 _fsql.Ado.MasterPool.Return(_conn);
1iKDfA.png
然后DbConnection 就被close并dispose了。

有没有啥解决办法?

@2881099

This comment has been minimized.

Copy link
Owner

@2881099 2881099 commented Jan 20, 2020

memory 模式有什么特征没,可以判断一下

@2881099

This comment has been minimized.

Copy link
Owner

@2881099 2881099 commented Jan 20, 2020

明白了,我兼容下

@tky753

This comment has been minimized.

Copy link
Contributor Author

@tky753 tky753 commented Jan 20, 2020

是否可以给FreeSqlBuilder增加一个UseDbConnection()

@tky753

This comment has been minimized.

Copy link
Contributor Author

@tky753 tky753 commented Jan 21, 2020

还有一个地方,也会Close DbConnection:

FreeSql\Providers\FreeSql.Provider.Sqlite\SqliteAdo\SqliteAdo.cs Line 23
@2881099

This comment has been minimized.

Copy link
Owner

@2881099 2881099 commented Jan 21, 2020

1.1.0-preview6 解决了该问题

方式一:

.UseConnectionString(DataType.Sqlite, "Data Source=:memory:")

方式二:

//定义单个连接对象
var conn = new SqliteConnection("Data Source=:memory:");

//FreeSqlBuilder 中
.UseConnectionString(DataType.Sqlite, () => conn)
2881099 pushed a commit that referenced this issue Jan 21, 2020
2881099 pushed a commit that referenced this issue Jan 21, 2020
@tky753 tky753 closed this Jan 21, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
2 participants
You can’t perform that action at this time.