Здравствуйте!
Данное задание было выдано преподавателем, вроде бы простое, но я довольно таки не лажу с базами данных.
Сначала я сделал добавление пользователей на сайт (через локальную БД), но когда я стал переключать на postgresql вылезла ошибка. По данной проблеме смотрел на разных сайтах ничего не помогло.
Проблема такова: Формат строки инициализации не соответствует спецификации, начиная с индекса 36 (Строка 16 - Контроллера)
Текст задания: (см.Вложения)
P.S: Пожалуйста не удивляйтесь названию проекта
Контроллер:
C# |
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
| namespace imdayn.Controllers
{
public class HomeController : Controller
{
PostgresqlContext _context;
public HomeController()
{
_context = new PostgresqlContext();
}
public ActionResult Index()
{
return View(_context.Users.ToList());
//return View(UserDataStorage.Instance.GetAllUsers().OrderBy(x => x.UserName));
//return View(db.Users.ToList());
}
public ActionResult Details(int id)
{
return View(UserDataStorage.Instance.GetUserByUserId(id));
}
public ActionResult Edit(int id)
{
return View(UserDataStorage.Instance.GetUserByUserId(id));
}
[HttpPost]
public ActionResult Edit(int id, UserModel model)
{
if (!TryUpdateModel(model))
{
return View(model);
}
UserDataStorage.Instance.UpdateUser(model);
return View("Details", model);
}
public ActionResult Create()
{
return View(new UserModel());
}
[HttpPost]
public ActionResult Create(UserModel model)
{
if (!TryUpdateModel(model))
{
return View(model);
}
//db.Users.Add(model);
UserDataStorage.Instance.CreateUser(model);
//return RedirectToAction("Details");
return View("Details", model);
}
public ActionResult Delete(int id)
{
return View(UserDataStorage.Instance.GetUserByUserId(id));
}
[HttpPost]
public ActionResult Delete(int id, FormCollection form)
{
UserDataStorage.Instance.DeleteUser(id);
return RedirectToAction("Index");
}
//public ActionResult About()
//{
// ViewBag.Message = "Your application description page.";
// return View();
//}
}
} |
|
Context
C# |
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
| namespace imdayn.Context
{
public class PostgresqlContext : DbContext
{
public virtual DbSet<UserModel> Users { get; set; }
public PostgresqlContext() : base(nameOrConnectionString: "PostgresqlContext")
{ }
}
} |
|
UserDataStorage
C# |
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
| namespace imdayn.Models
{
public class UserDataStorage
{
public static UserDataStorage Instance = new UserDataStorage();
private List<UserModel> userList = new List<UserModel>();
public UserDataStorage()
{
this.userList.Add(
new UserModel
{
UserId = 1,
UserName = "Comrade",
FirstName = "Gusev Andrey Igorevich",
Password = "241421412wrqfs"
});
}
public List<UserModel> GetAllUsers()
{
return this.userList;
}
public UserModel GetUserByUserId(int userId)
{
return this.userList.Find(x => x.UserId == userId);
}
public void UpdateUser(UserModel model)
{
var oldModel = this.userList.Find(x => x.UserId == model.UserId);
//if (oldModel)
//{
// return null;
//}
this.userList.Remove(oldModel);
this.userList.Add(model);
}
public void CreateUser(UserModel model)
{
if (this.userList.Exists(x => x.UserName == model.UserName))
{
throw new InvalidOperationException();
}
model.UserId = this.userList.Max(x => x.UserId) + 1;
this.userList.Add(model);
}
public void DeleteUser(int userId)
{
var model = this.userList.Find(x => x.UserId == userId);
if(model == null)
{
return;
}
this.userList.Remove(model);
}
}
} |
|
Web.cfg
XML |
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
| <configuration>
<configSections>
<!-- For more information on Entity Framework configuration, visit http://go.microsoft.com/fwlink/?LinkID=237468 -->
<section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
<!-- For more information on Entity Framework configuration, visit http://go.microsoft.com/fwlink/?LinkID=237468 -->
</configSections>
<connectionStrings>
<add name="PostgresqlContext" providerName="Npgsql" connectionString="Server=192.168.1.200;User Id=parser;Password=Ckj';'y1sqg1123fhj4km;Port=5432;Database=parser;"/>
<!--<add name="DefaultConnection" connectionString="Data Source=(LocalDb)\MSSQLLocalDB;AttachDbFilename=|DataDirectory|\aspnet-imdayn-20220530124058.mdf;Initial Catalog=aspnet-imdayn-20220530124058;Integrated Security=True" providerName="System.Data.SqlClient" />-->
</connectionStrings>
<appSettings>
<add key="webpages:Version" value="3.0.0.0" />
<add key="webpages:Enabled" value="false" />
<add key="ClientValidationEnabled" value="true" />
<add key="UnobtrusiveJavaScriptEnabled" value="true" />
</appSettings>
<system.web>
<authentication mode="None" />
<compilation debug="true" targetFramework="4.7.2" />
<httpRuntime targetFramework="4.7.2" />
</system.web>
<system.webServer>
<modules>
<remove name="FormsAuthentication" />
</modules>
</system.webServer>
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="Microsoft.Owin.Security" publicKeyToken="31bf3856ad364e35" />
<bindingRedirect oldVersion="0.0.0.0-4.0.1.0" newVersion="4.0.1.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="Microsoft.Owin.Security.OAuth" publicKeyToken="31bf3856ad364e35" />
<bindingRedirect oldVersion="0.0.0.0-4.0.1.0" newVersion="4.0.1.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="Microsoft.Owin.Security.Cookies" publicKeyToken="31bf3856ad364e35" />
<bindingRedirect oldVersion="0.0.0.0-4.0.1.0" newVersion="4.0.1.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="Microsoft.Owin" publicKeyToken="31bf3856ad364e35" />
<bindingRedirect oldVersion="0.0.0.0-4.0.1.0" newVersion="4.0.1.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="Antlr3.Runtime" publicKeyToken="eb42632606e9261f" />
<bindingRedirect oldVersion="0.0.0.0-3.5.0.2" newVersion="3.5.0.2" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="System.Web.Optimization" publicKeyToken="31bf3856ad364e35" />
<bindingRedirect oldVersion="0.0.0.0-1.1.0.0" newVersion="1.1.0.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="WebGrease" publicKeyToken="31bf3856ad364e35" />
<bindingRedirect oldVersion="0.0.0.0-1.6.5135.21930" newVersion="1.6.5135.21930" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="Newtonsoft.Json" publicKeyToken="30ad4fe6b2a6aeed" />
<bindingRedirect oldVersion="0.0.0.0-12.0.0.0" newVersion="12.0.0.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="System.Web.Helpers" publicKeyToken="31bf3856ad364e35" />
<bindingRedirect oldVersion="0.0.0.0-3.0.0.0" newVersion="3.0.0.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="System.Web.Mvc" publicKeyToken="31bf3856ad364e35" />
<bindingRedirect oldVersion="0.0.0.0-5.2.7.0" newVersion="5.2.7.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="System.Web.WebPages" publicKeyToken="31bf3856ad364e35" />
<bindingRedirect oldVersion="0.0.0.0-3.0.0.0" newVersion="3.0.0.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="System.Runtime.CompilerServices.Unsafe" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-6.0.0.0" newVersion="6.0.0.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="System.Buffers" publicKeyToken="cc7b13ffcd2ddd51" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-4.0.3.0" newVersion="4.0.3.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="Npgsql" publicKeyToken="5d8b90d52f46fda7" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-6.0.4.0" newVersion="6.0.4.0" />
</dependentAssembly>
</assemblyBinding>
</runtime>
<entityFramework>
<providers>
<provider invariantName="System.Data.SqlClient" type="System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer" />
<provider invariantName="Npgsql" type="Npgsql.NpgsqlServices, EntityFramework6.Npgsql" />
</providers>
<defaultConnectionFactory type="Npgsql.NpgsqlConnectionFactory, EntityFramework6.Npgsql" />
</entityFramework>
<system.data>
<DbProviderFactories>
<add name="Npgsql Data Provider" invariant="Npgsql" support="FF" description=".Net Framework Data Provider for Postgresql" type="Npgsql.NpgsqlFactory, Npgsql" />
<remove invariant="Npgsql" />
<add name="Npgsql Provider" invariant="Npgsql" description=".NET Framework Data Provider for PostgreSQL" type="Npgsql.NpgsqlFactory, Npgsql, Version=4.1.3.0, Culture=neutral, PublicKeyToken=5d8b90d52f46fda7" />
</DbProviderFactories>
</system.data>
<system.codedom>
<compilers>
<compiler language="c#;cs;csharp" extension=".cs" type="Microsoft.CodeDom.Providers.DotNetCompilerPlatform.CSharpCodeProvider, Microsoft.CodeDom.Providers.DotNetCompilerPlatform, Version=2.0.1.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" warningLevel="4" compilerOptions="/langversion:default /nowarn:1659;1699;1701" />
<compiler language="vb;vbs;visualbasic;vbscript" extension=".vb" type="Microsoft.CodeDom.Providers.DotNetCompilerPlatform.VBCodeProvider, Microsoft.CodeDom.Providers.DotNetCompilerPlatform, Version=2.0.1.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" warningLevel="4" compilerOptions="/langversion:default /nowarn:41008 /define:_MYTYPE=\"Web\" /optionInfer+" />
</compilers>
</system.codedom>
</configuration> |
|
Модель User
C# |
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
| namespace imdayn.Models
{
[Table("Users", Schema = "public")]
public class UserModel
{
[Key]
public int UserId { get; set; }
[Display(Name = "Логин")]
public string UserName { get; set; }
[Display(Name = "ФИО")]
public string FirstName { get; set; }
[Display(Name = "Пароль")]
public string Password { get; set; }
}
} |
|
Помогите найти ошибку