I created a working Data-Based Database. I can also use this db with the DataGridView.
But how can I create a connection to the database with C#? I searched already before but nothing worked for me.
In my App.config is also
<connectionStrings>
<add name="make_it_server_verwaltung.Properties.Settings.ServerlistConnectionString"
connectionString="Data Source=(LocalDB)\MSSQLLocalDB;AttachDbFilename=|DataDirectory|\Serverlist.mdf;Integrated Security=True"
providerName="System.Data.SqlClient" />
</connectionStrings>
So how can I create a connection to my db and how can I add/delete/change/read my database over C#?
Thank you ^^
Working DataGridView
Related
I'm developing a Windows Forms application that I need to storage some data as a database in user's system, so that I would be able to access my database through Entity Framework. I mean I need to copy a database (tables should be created already) from the resources directory to specific directory. Then use it with Entity Framework. To be honest I have no idea. That's my problem!
I make sample fixed problem for all project when create winforms & localdb
You can create 2 ConnectionString in App.config file
App.config
<add name="DevConnectionString"
connectionString="Data Source=(LocalDB)\MSSQLLocalDB;AttachDbFilename=|DataDirectory|\MyDatabase.mdf;Integrated Security=True"
providerName="System.Data.SqlClient" /> <!-- *1* Use when publish project-->
<!--<add name="AppConnectionString"
connectionString="Data Source=(LocalDB)\MSSQLLocalDB;AttachDbFilename='E:\My Projects\MyDatabase.mdf';Integrated Security=True"
providerName="System.Data.SqlClient" />-->
<!--*2* Use for development-->
Hi I am not able to connect I get an error server was not found, the problem is my connection string in the data source property in web config.
<connectionStrings>
<add name="dbHolaStaffConnectionString" connectionString="Data Source=localhost\SQL2016;Initial Catalog=dbHolaStaff;user id=xx;password=xx;MultipleActiveResultSets=True;Application Name=EntityFramework" providerName="System.Data.SqlClient" />
</connectionStrings>
I have chnaged the source in many ways but cant get it work.
DESKTOP-VNAJJMF\SQL2016
.\SQL2016
localhost\SQL2016
The server name in sql management studio is: DESKTOP-VNAJJMF\SQL2016
My user id and passwords are correct, how can I fix this problem? I dont know why visual studios keeps showing that error.
I also have enabled Remote access in sql server but nothing works.
Can you try with the below one
<connectionStrings>
<add name="dbHolaStaffConnectionString" connectionString="Server=DESKTOP-VNAJJMF\SQL2016;Database=dbHolaStaff;user id=xx;password=xx;MultipleActiveResultSets=True;Trusted_Connection=True;Application Name=EntityFramework" providerName="System.Data.SqlClient" />
</connectionStrings>
I'm about to send my Visual Studio project (C#, ASP.NET) and database (MS Access) to someone who will upload it into a server (don't know which one).
However, given that database file will be at the same map with the project, how do I prepare my connection string for that database? So far I worked local at my computer, including the database.
This is how my connection looks like in web.config, what changes do I need to make?
<connectionStrings>
<add name="DatabaseConnectionString"
connectionString="Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\Project\etc\DATABASE.mdb"
providerName="System.Data.OleDb" />
<add name="DatabaseConnectionString1"
connectionString="Provider=Microsoft.Jet.OLEDB.4.0;Data Source=|DataDirectory|\DATABASE.mdb"
providerName="System.Data.OleDb" />
</connectionStrings>
Any help would be greatly appreciated.
I tried many things and saw a lot of information on the internet. It just doesn't work and I want to know what am I doing wrong.
I created a .mdf database in my App_Data folder and trying to connect it through Web.config.
my <connectionString /> looks like this:
<add name="Datab1" connectionString="Data Source=.\SQLExpress;AttachDbFilename=|DataDirectory|Datab1.mdf;Database=Datab1; Trusted_Connection=Yes;" />
And I also tried this:
<add name="Datab1" connectionString="Data Source=.\SQLEXPRESS;
AttachDbFilename=E:\Secret\Secret\App_Data\Datab1.mdf;
Integrated Security=True;
User Instance=True"/>
The providerName="System.Data.Client" />gives me an error so I removed it.
What am I doing wrong here?
I finally fixed it by going to Server Explorer > Connect to Database > Data source to "Microsoft SQL Server Database File (SqlClient)" and Db file name browse to the .mdf file you want to use. Use Windows Authentication.
in the Web.config use this string:
<add name="Datab1" connectionString="Data Source=(localdb)\v11.0;AttachDbFileName=path\to\folder\of\database\Datab1.mdf;Integrated Security=True" providerName="System.Data.SqlClient"/>
And replace Datab1 with your own database name of course. This worked for me so this question is solved!
I have completed my project in c#. I have used SQL Server Compact database (.sdf file). Now, when I compile and run, it works fine. But, how will I be able to run the application in other computers without configuring the connection to database?
In your App.config file add the following after </configSections>:
<connectionStrings>
<add name="NameOfYourConnectionString" connectionString="Data Source=.; AttachDbFilename=|DataDirectory|\student.sdf;Initial Catalog=student; Integrated Security=True" providerName="System.Data.SqlClient" />
</connectionStrings>