sql-server-express

SQL/C# - Best method for executing a query

别来无恙 提交于 2019-11-26 14:48:24
问题 I need to execute a sql query from within a c# class. I have thought of 2 options Starting a process of sqlcmd. Using a SqlCommand object. My question is which would be the better way? It's important that the solution only holds a connection to the server for a short time. I'm open to other ideas if the above aren't good. Thanks in advance. 回答1: Use a SqlCommand. This code will only keep the connection alive for a very short period of time (as long as your query is performant): DataTable

SQL command INSERT is working but the data not appear in table

冷暖自知 提交于 2019-11-26 11:56:16
I am executing SQL command INSERT like this in my Visual C#.NET using MS VS 2010 Express Edition: private void btnAdd_Click(object sender, EventArgs e) { SqlConnection con = new SqlConnection(Properties.Settings.Default.loginDBConnectionString); con.Open(); SqlCommand cmd = new SqlCommand("INSERT INTO tblEmp (ID, firstname, lastname, email, position) VALUES ('"+textBox1.Text+"','"+textBox2.Text+"', '"+textBox3.Text+"', '"+textBox4.Text+"', '"+comboBox1.Text+"')", con); cmd.ExecuteNonQuery(); con.Close(); MessageBox.Show("Data Added!"); } When executing this, the MessageBox showed up which

How can I schedule a daily backup with SQL Server Express? [duplicate]

对着背影说爱祢 提交于 2019-11-26 11:49:07
问题 This question already has an answer here: SQL Server Automated Backups [closed] 3 answers I\'m running a small web application with SQL server express (2005) as backend. I can create a backup with a SQL script, however, I\'d like to schedule this on a daily basis. As extra option (should-have) I\'d like to keep only the last X backups (for space-saving reasons obviously) Any pointers? [edit] SQL server agent is unavailable in SQL server express... 回答1: You cannot use the SQL Server agent in

“Cannot open user default database. Login failed.” after installing SQL Server Management Studio Express

南笙酒味 提交于 2019-11-26 11:29:57
问题 I have a database in a local file that is used by a program. The program has limited functionality and I needed to run some quick queries. I installed SQL Server Management Studio Express 2005 (SSMSE), connected to the SQL Server instance, attached the database file, and ran the queries. Now the original program will no longer connect to the database. I receive the error: Cannot open user default database. Login failed. Login failed for user \'MyComputer\\MyUserName\'. I\'ve gone back into

Can SQL Server Express LocalDB be connected to remotely?

[亡魂溺海] 提交于 2019-11-26 11:29:00
问题 I am looking into using the new SQL Server Express LocalDB (I think it is code named \"Denali\") for a desktop application. It is currently running with SQL Compact, but the user is wanting to share the database between multiple PCs on a network. Unfortunately this is not something that SQL Compact can do, so I am investigating other solutions. The client requires the ability to send database files easily to other sites or to back them up to a flash disk, so I am avoiding going to SQL Express

SQL Express connection string: mdf file location relative to application location

戏子无情 提交于 2019-11-26 10:30:03
I am using SQL Express databases as part of a unit test project in c#. My databases is located here: ./Databases/MyUnitTestDB.mdf I would like to use a relative path or variable in the app.config rather than having my connection string defined as: AttachDbFilename=C:\blah\blah\blah\yea\yea\yea\MyApplication\Databases\MyUnitTestDB.mdf I have seen the use of |DataDirectory| but am I correct in thinking this is only applicable to web applications? I want to control this in the application configuration file, as in production the application uses a hosted sql database. Thanks everyone, I used a

How to run a stored procedure every day in SQL Server Express Edition?

巧了我就是萌 提交于 2019-11-26 09:08:41
问题 How is it possible to run a stored procedure at a particular time every day in SQL Server Express Edition? Notes: This is needed to truncate an audit table An alternative would be to modify the insert query but this is probably less efficient SQL Server Express Edition does not have the SQL Server Agent Related Questions: How can I schedule a daily backup with SQl Server Express? Scheduled run of stored procedure on SQL Server 回答1: Since SQL Server express does not come with SQL Agent, you

SQL Insert Query Using C#

▼魔方 西西 提交于 2019-11-26 07:37:14
问题 I\'m having an issue at the moment which I am trying to fix. I just tried to access a database and insert some values with the help of C# The things I tried (worked) String query = \"INSERT INTO dbo.SMS_PW (id,username,password,email) VALUES (\'abc\', \'abc\', \'abc\', \'abc\')\"; A new line was inserted and everything worked fine, now I tried to insert a row using variables: String query = \"INSERT INTO dbo.SMS_PW (id,username,password,email) VALUES (@id, @username, @password, @email)\";

SQL Server Express connection string for Entity Framework Code First

纵然是瞬间 提交于 2019-11-26 07:27:28
问题 I am working in Visual Web Developer 2010 Express, and using the Entity Framework code-first CTP. I am able to do this with the new SQL Server CE but I am unable to find a connection string to work with SQL Server Express. This one, using the SQL Server CE beta, works fine (database is created and recreated on model changes). <add name=\"TrempimModel\" connectionString=\"data source=|DataDirectory|TrempimModel.sdf\" providerName=\"System.Data.SqlServerCe.4.0\" /> This one, which I copied from

SQL Server named instance with Visual Studio 2017 Installer project

只愿长相守 提交于 2019-11-26 06:08:23
问题 Software: SQL Server Express 2016 Visual Studio 2017 We\'ve been trying without success to get a named instance of SQL Server Express 2016 installed as part of VS Installer Setup Project. We\'ve tried calling InstallNamedInstance() as follows with given results: Run SQLEXPR_x64_ENU.exe with same commandline args from Administrator cmd window: Succeeds Call InstallNamedInstance() from a Console app and run Console app from Administrator cmd window: Succeeds Install custom action (Both Everyone