iis asp.net core 5 上的 Firebird 读取数据库问题
Firebird reading database issue on iis asp.net core 5
我想在 ASP.NET 带有嵌入式 Firebird v2.5 的 Core MVC 中开发一个演示项目。我从文本文件中读取了 Firebird 连接字符串信息。因为我将在项目演示中更改数据库,所以我必须从文本文件中读取。或者你的想法是什么?
在这个项目中,我创建了一个 DbContext
文件,并使用 class:
填写数据库信息
public class DbContext
{
string startupdirectory = Path.GetDirectoryName(System.Reflection.Assembly.GetEntryAssembly().Location)+"\settings.txt";
string dblocation = string.Empty;
string userName = string.Empty;
string pass = string.Empty;
int port = 0;
string dataSource = string.Empty;
public DbContext()
{
if (File.Exists(startupdirectory))
{
string[] allData = File.ReadAllLines(startupdirectory);
dblocation = allData[0].ToString();
userName = allData[1].ToString();
pass = allData[2].ToString();
port = Convert.ToInt32(allData[3].ToString());
dataSource = allData[4].ToString();
}
}
public string GetConnectionString()
{
FbConnectionStringBuilder csb = new();
csb.Database = dblocation;
csb.DataSource = dataSource;
csb.UserID = userName;
csb.Password = pass;
csb.ServerType = FbServerType.Default;
csb.Port = port;
//i added below code for embedded db
csb.Dialect = 3;
csb.Role = "";
csb.ConnectionLifeTime = 15;
csb.Pooling = true;
csb.MinPoolSize = 0;
csb.MaxPoolSize = 50;
csb.PacketSize = 8192;
return csb.ToString();
}
public FbConnection GetConnection()
{
string connectionString = GetConnectionString();
FbConnection connection = new();
connection.ConnectionString = connectionString;
connection.Open();
return connection;
}
public void KillConnection(FbConnection connection)
{
connection.Close();
connection.Dispose();
}
}
当我在本地工作时,一切都很好。我可以做所有的CRUD操作。
但是当我上传我的项目时,我看到了这个屏幕:
An unhandled exception occurred while processing the request.
IscException: I/O error during "CreateFile (open)" operation for file "C:\Firma\BlinePalmeWEB\MandantenPalmeIT\GDI21.FDB"
Error while trying to open file
FirebirdSql.Data.Client.Managed.GdsConnection.HandleResponseException(IResponse response)
FbException: I/O error during "CreateFile (open)" operation for file "C:\Firma\BlinePalmeWEB\MandantenPalmeIT\GDI21.FDB"
Error while trying to open file
FirebirdSql.Data.FirebirdClient.FbConnectionInternal.Connect()
Stack Query Cookies Headers Routing
IscException: I/O error during "CreateFile (open)" operation for file "C:\Firma\BlinePalmeWEB\MandantenPalmeIT\GDI21.FDB" Error while trying to open file
FirebirdSql.Data.Client.Managed.GdsConnection.HandleResponseException(IResponse response)
FirebirdSql.Data.Client.Managed.Version10.GdsDatabase.ReadResponse()
FirebirdSql.Data.Client.Managed.Version10.GdsDatabase.Attach(DatabaseParameterBufferBase dpb, string database, byte[] cryptKey)
FirebirdSql.Data.FirebirdClient.FbConnectionInternal.Connect()
Show raw exception details
FbException: I/O error during "CreateFile (open)" operation for file "C:\Firma\BlinePalmeWEB\Mandanten\11PalmeIT\GDI21.FDB" Error while trying to open file
FirebirdSql.Data.FirebirdClient.FbConnectionInternal.Connect()
FirebirdSql.Data.FirebirdClient.FbConnection.Open()
GDIWebApplication.Controllers.DbContext.GetConnection() in DbContext.cs
GDIWebApplication.Models.Deneme.ProductRepository.GetArtikelList() in ProductRepository.cs
GDIWebApplication.Controllers.ProductController.Index(string search) in ProductController.cs
lambda_method1(Closure , object , object[] )
Microsoft.AspNetCore.Mvc.Infrastructure.ActionMethodExecutor+SyncActionResultExecutor.Execute(IActionResultTypeMapper mapper, ObjectMethodExecutor executor, object controller, object[] arguments)
Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.InvokeActionMethodAsync()
Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.Next(ref State next, ref Scope scope, ref object state, ref bool isCompleted)
Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.InvokeNextActionFilterAsync()
Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.Rethrow(ActionExecutedContextSealed context)
Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.Next(ref State next, ref Scope scope, ref object state, ref bool isCompleted)
Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.InvokeInnerFilterAsync()
Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.<InvokeNextResourceFilter>g__Awaited|24_0(ResourceInvoker invoker, Task lastTask, State next, Scope scope, object state, bool isCompleted)
Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.Rethrow(ResourceExecutedContextSealed context)
Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.Next(ref State next, ref Scope scope, ref object state, ref bool isCompleted)
Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.InvokeFilterPipelineAsync()
Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.<InvokeAsync>g__Awaited|17_0(ResourceInvoker invoker, Task task, IDisposable scope)
Microsoft.AspNetCore.Routing.EndpointMiddleware.<Invoke>g__AwaitRequestTask|6_0(Endpoint endpoint, Task requestTask, ILogger logger)
Microsoft.AspNetCore.Authorization.AuthorizationMiddleware.Invoke(HttpContext context)
Microsoft.AspNetCore.Diagnostics.DeveloperExceptionPageMiddleware.Invoke(HttpContext context)
Show raw exception details
FirebirdSql.Data.FirebirdClient.FbException (0x80004005): I/O error during "CreateFile (open)" operation for file "C:\Firma\BlinePalmeWEB\Mandanten\11PalmeIT\GDI21.FDB"
Error while trying to open file
---> FirebirdSql.Data.Common.IscException: I/O error during "CreateFile (open)" operation for file "C:\Firma\BlinePalmeWEB\Mandanten\11PalmeIT\GDI21.FDB"
Error while trying to open file
at FirebirdSql.Data.Client.Managed.GdsConnection.HandleResponseException(IResponse response)
at FirebirdSql.Data.Client.Managed.Version10.GdsDatabase.ReadResponse()
at FirebirdSql.Data.Client.Managed.Version10.GdsDatabase.Attach(DatabaseParameterBufferBase dpb, String database, Byte[] cryptKey)
at FirebirdSql.Data.FirebirdClient.FbConnectionInternal.Connect()
at FirebirdSql.Data.FirebirdClient.FbConnectionInternal.Connect()
at FirebirdSql.Data.FirebirdClient.FbConnection.Open()
at GDIWebApplication.Controllers.DbContext.GetConnection() in C:\Users\MD\source\repos\GDIWebApplication\Models\Context\DbContext.cs:line 60
at GDIWebApplication.Models.Deneme.ProductRepository.GetArtikelList() in C:\Users\MD\source\repos\GDIWebApplication\Models\Repositories\ProductRepository.cs:line 20
at GDIWebApplication.Controllers.ProductController.Index(String search) in C:\Users\MD\source\repos\GDIWebApplication\Controllers\ProductController.cs:line 16
at lambda_method1(Closure , Object , Object[] )
at Microsoft.AspNetCore.Mvc.Infrastructure.ActionMethodExecutor.SyncActionResultExecutor.Execute(IActionResultTypeMapper mapper, ObjectMethodExecutor executor, Object controller, Object[] arguments)
at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.InvokeActionMethodAsync()
at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.Next(State& next, Scope& scope, Object& state, Boolean& isCompleted)
at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.InvokeNextActionFilterAsync()
--- End of stack trace from previous location ---
at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.Rethrow(ActionExecutedContextSealed context)
at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.Next(State& next, Scope& scope, Object& state, Boolean& isCompleted)
at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.InvokeInnerFilterAsync()
--- End of stack trace from previous location ---
at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.<InvokeNextResourceFilter>g__Awaited|24_0(ResourceInvoker invoker, Task lastTask, State next, Scope scope, Object state, Boolean isCompleted)
at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.Rethrow(ResourceExecutedContextSealed context)
at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.Next(State& next, Scope& scope, Object& state, Boolean& isCompleted)
at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.InvokeFilterPipelineAsync()
--- End of stack trace from previous location ---
at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.<InvokeAsync>g__Awaited|17_0(ResourceInvoker invoker, Task task, IDisposable scope)
at Microsoft.AspNetCore.Routing.EndpointMiddleware.<Invoke>g__AwaitRequestTask|6_0(Endpoint endpoint, Task requestTask, ILogger logger)
at Microsoft.AspNetCore.Authorization.AuthorizationMiddleware.Invoke(HttpContext context)
at Microsoft.AspNetCore.Diagnostics.DeveloperExceptionPageMiddleware.Invoke(HttpContext context)
我添加的所有权限都是 IIS,但我无法正常工作 - 我该如何解决这个问题?
您没有使用嵌入式 Firebird。正如您指定的 FbServerType.Default
(这也是默认值),您正在使用 TCP/IP 通过普通的 Firebird 服务器进行连接,错误表明数据库文件不存在(或者可能是 Firebird 服务器进程没有足够的访问权限来打开文件)。
如果你真的想使用 Firebird Embedded(我个人认为这对于服务器应用程序来说不是一个好主意),你需要指定 FbServerType.Embedded
。还要确保数据库文件实际存在于 dataSource
.
指定的服务器上的 C:\Firma\BlinePalmeWEB\MandantenPalmeIT\GDI21.FDB
处
我想在 ASP.NET 带有嵌入式 Firebird v2.5 的 Core MVC 中开发一个演示项目。我从文本文件中读取了 Firebird 连接字符串信息。因为我将在项目演示中更改数据库,所以我必须从文本文件中读取。或者你的想法是什么?
在这个项目中,我创建了一个 DbContext
文件,并使用 class:
public class DbContext
{
string startupdirectory = Path.GetDirectoryName(System.Reflection.Assembly.GetEntryAssembly().Location)+"\settings.txt";
string dblocation = string.Empty;
string userName = string.Empty;
string pass = string.Empty;
int port = 0;
string dataSource = string.Empty;
public DbContext()
{
if (File.Exists(startupdirectory))
{
string[] allData = File.ReadAllLines(startupdirectory);
dblocation = allData[0].ToString();
userName = allData[1].ToString();
pass = allData[2].ToString();
port = Convert.ToInt32(allData[3].ToString());
dataSource = allData[4].ToString();
}
}
public string GetConnectionString()
{
FbConnectionStringBuilder csb = new();
csb.Database = dblocation;
csb.DataSource = dataSource;
csb.UserID = userName;
csb.Password = pass;
csb.ServerType = FbServerType.Default;
csb.Port = port;
//i added below code for embedded db
csb.Dialect = 3;
csb.Role = "";
csb.ConnectionLifeTime = 15;
csb.Pooling = true;
csb.MinPoolSize = 0;
csb.MaxPoolSize = 50;
csb.PacketSize = 8192;
return csb.ToString();
}
public FbConnection GetConnection()
{
string connectionString = GetConnectionString();
FbConnection connection = new();
connection.ConnectionString = connectionString;
connection.Open();
return connection;
}
public void KillConnection(FbConnection connection)
{
connection.Close();
connection.Dispose();
}
}
当我在本地工作时,一切都很好。我可以做所有的CRUD操作。
但是当我上传我的项目时,我看到了这个屏幕:
An unhandled exception occurred while processing the request.
IscException: I/O error during "CreateFile (open)" operation for file "C:\Firma\BlinePalmeWEB\MandantenPalmeIT\GDI21.FDB"
Error while trying to open file
FirebirdSql.Data.Client.Managed.GdsConnection.HandleResponseException(IResponse response)
FbException: I/O error during "CreateFile (open)" operation for file "C:\Firma\BlinePalmeWEB\MandantenPalmeIT\GDI21.FDB"
Error while trying to open file
FirebirdSql.Data.FirebirdClient.FbConnectionInternal.Connect()Stack Query Cookies Headers Routing
IscException: I/O error during "CreateFile (open)" operation for file "C:\Firma\BlinePalmeWEB\MandantenPalmeIT\GDI21.FDB" Error while trying to open file FirebirdSql.Data.Client.Managed.GdsConnection.HandleResponseException(IResponse response) FirebirdSql.Data.Client.Managed.Version10.GdsDatabase.ReadResponse() FirebirdSql.Data.Client.Managed.Version10.GdsDatabase.Attach(DatabaseParameterBufferBase dpb, string database, byte[] cryptKey) FirebirdSql.Data.FirebirdClient.FbConnectionInternal.Connect()
Show raw exception details
FbException: I/O error during "CreateFile (open)" operation for file "C:\Firma\BlinePalmeWEB\Mandanten\11PalmeIT\GDI21.FDB" Error while trying to open file
FirebirdSql.Data.FirebirdClient.FbConnectionInternal.Connect()
FirebirdSql.Data.FirebirdClient.FbConnection.Open()
GDIWebApplication.Controllers.DbContext.GetConnection() in DbContext.cs
GDIWebApplication.Models.Deneme.ProductRepository.GetArtikelList() in ProductRepository.cs
GDIWebApplication.Controllers.ProductController.Index(string search) in ProductController.cs
lambda_method1(Closure , object , object[] )
Microsoft.AspNetCore.Mvc.Infrastructure.ActionMethodExecutor+SyncActionResultExecutor.Execute(IActionResultTypeMapper mapper, ObjectMethodExecutor executor, object controller, object[] arguments)
Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.InvokeActionMethodAsync()
Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.Next(ref State next, ref Scope scope, ref object state, ref bool isCompleted)
Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.InvokeNextActionFilterAsync()
Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.Rethrow(ActionExecutedContextSealed context)
Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.Next(ref State next, ref Scope scope, ref object state, ref bool isCompleted)
Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.InvokeInnerFilterAsync()
Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.<InvokeNextResourceFilter>g__Awaited|24_0(ResourceInvoker invoker, Task lastTask, State next, Scope scope, object state, bool isCompleted)
Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.Rethrow(ResourceExecutedContextSealed context)
Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.Next(ref State next, ref Scope scope, ref object state, ref bool isCompleted)
Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.InvokeFilterPipelineAsync()
Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.<InvokeAsync>g__Awaited|17_0(ResourceInvoker invoker, Task task, IDisposable scope)
Microsoft.AspNetCore.Routing.EndpointMiddleware.<Invoke>g__AwaitRequestTask|6_0(Endpoint endpoint, Task requestTask, ILogger logger)
Microsoft.AspNetCore.Authorization.AuthorizationMiddleware.Invoke(HttpContext context)
Microsoft.AspNetCore.Diagnostics.DeveloperExceptionPageMiddleware.Invoke(HttpContext context)
Show raw exception details
FirebirdSql.Data.FirebirdClient.FbException (0x80004005): I/O error during "CreateFile (open)" operation for file "C:\Firma\BlinePalmeWEB\Mandanten\11PalmeIT\GDI21.FDB"
Error while trying to open file
---> FirebirdSql.Data.Common.IscException: I/O error during "CreateFile (open)" operation for file "C:\Firma\BlinePalmeWEB\Mandanten\11PalmeIT\GDI21.FDB"
Error while trying to open file
at FirebirdSql.Data.Client.Managed.GdsConnection.HandleResponseException(IResponse response)
at FirebirdSql.Data.Client.Managed.Version10.GdsDatabase.ReadResponse()
at FirebirdSql.Data.Client.Managed.Version10.GdsDatabase.Attach(DatabaseParameterBufferBase dpb, String database, Byte[] cryptKey)
at FirebirdSql.Data.FirebirdClient.FbConnectionInternal.Connect()
at FirebirdSql.Data.FirebirdClient.FbConnectionInternal.Connect()
at FirebirdSql.Data.FirebirdClient.FbConnection.Open()
at GDIWebApplication.Controllers.DbContext.GetConnection() in C:\Users\MD\source\repos\GDIWebApplication\Models\Context\DbContext.cs:line 60
at GDIWebApplication.Models.Deneme.ProductRepository.GetArtikelList() in C:\Users\MD\source\repos\GDIWebApplication\Models\Repositories\ProductRepository.cs:line 20
at GDIWebApplication.Controllers.ProductController.Index(String search) in C:\Users\MD\source\repos\GDIWebApplication\Controllers\ProductController.cs:line 16
at lambda_method1(Closure , Object , Object[] )
at Microsoft.AspNetCore.Mvc.Infrastructure.ActionMethodExecutor.SyncActionResultExecutor.Execute(IActionResultTypeMapper mapper, ObjectMethodExecutor executor, Object controller, Object[] arguments)
at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.InvokeActionMethodAsync()
at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.Next(State& next, Scope& scope, Object& state, Boolean& isCompleted)
at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.InvokeNextActionFilterAsync()
--- End of stack trace from previous location ---
at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.Rethrow(ActionExecutedContextSealed context)
at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.Next(State& next, Scope& scope, Object& state, Boolean& isCompleted)
at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.InvokeInnerFilterAsync()
--- End of stack trace from previous location ---
at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.<InvokeNextResourceFilter>g__Awaited|24_0(ResourceInvoker invoker, Task lastTask, State next, Scope scope, Object state, Boolean isCompleted)
at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.Rethrow(ResourceExecutedContextSealed context)
at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.Next(State& next, Scope& scope, Object& state, Boolean& isCompleted)
at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.InvokeFilterPipelineAsync()
--- End of stack trace from previous location ---
at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.<InvokeAsync>g__Awaited|17_0(ResourceInvoker invoker, Task task, IDisposable scope)
at Microsoft.AspNetCore.Routing.EndpointMiddleware.<Invoke>g__AwaitRequestTask|6_0(Endpoint endpoint, Task requestTask, ILogger logger)
at Microsoft.AspNetCore.Authorization.AuthorizationMiddleware.Invoke(HttpContext context)
at Microsoft.AspNetCore.Diagnostics.DeveloperExceptionPageMiddleware.Invoke(HttpContext context)
我添加的所有权限都是 IIS,但我无法正常工作 - 我该如何解决这个问题?
您没有使用嵌入式 Firebird。正如您指定的 FbServerType.Default
(这也是默认值),您正在使用 TCP/IP 通过普通的 Firebird 服务器进行连接,错误表明数据库文件不存在(或者可能是 Firebird 服务器进程没有足够的访问权限来打开文件)。
如果你真的想使用 Firebird Embedded(我个人认为这对于服务器应用程序来说不是一个好主意),你需要指定 FbServerType.Embedded
。还要确保数据库文件实际存在于 dataSource
.
C:\Firma\BlinePalmeWEB\MandantenPalmeIT\GDI21.FDB
处