sqlconnection

Getting system tables and views thru SqlConnection

不问归期 提交于 2019-12-11 21:19:15
问题 I am trying to get all tables from a LocalDB database in C# (VS 2012) When using an OleDbConnection I can do string[] restrictions = new string[4]; connection.GetSchema("Tables", restrictions); and it will return all user tables, all system views and all system tables How can I do this with a SqlConnection ? It seems that GetSchema on a SqlConnection only returns user tables and views, but no system tables or views. The 4th restriction parameter only seems to accept VIEW and BASE TABLE.

Concept of handling SqlCommand in C#

孤街醉人 提交于 2019-12-11 20:07:57
问题 I'm trying to select a list of users from the database and send email to each of every users based on a condition isSent == false. After send email to them, the value of this false should be update to true. Below code is the way i retrieve list of users from database and call method sendEmail() to each of them. myConnection.Open(); //******* try { SqlDataReader myReader = null; string sql = "SELECT * FROM testTable where isSent = false"; SqlCommand myCommand = new SqlCommand(sql, myConnection

Getting an sql connection string error when scaffolding in EF core?

﹥>﹥吖頭↗ 提交于 2019-12-11 15:39:06
问题 For background info, I'm running .NET core on Arch Linux VScode and I also have SQL Server running on Arch Linux. When I connect to the server via sqlcmd or through the VScode SQL extension, everything works fine. Only when scaffolding am I getting errors, so my connection string is probably wrong, and I've searched and basically tried everything within my grasp. Any help would be much appreciated, thanks in advance. When I run the command [wasiim@wasiim-PC WebApiServerApp]$ dotnet ef

Why is my SQL Server query failing?

醉酒当歌 提交于 2019-12-11 14:56:42
问题 connect(); $arr = mssql_fetch_assoc(mssql_query("SELECT Applications.ProductName, Applications.ProductVersion, Applications.ProductSize, Applications.Description, Applications.ProductKey, Applications.ProductKeyID, Applications.AutomatedInstaller, Applications.AutomatedInstallerName, Applications.ISO, Applications.ISOName, Applications.Internet, Applications.InternetURL, Applications.DatePublished, Applications.LicenseID, Applications.InstallationGuide, Vendors.VendorName FROM Applications

SQL Server return Select statement with XML datatype and convert it into DataSet in C#, ASP.Net

二次信任 提交于 2019-12-11 14:49:21
问题 In my database table, I have a column name 'SectionDatatable' which are in XML datatype. In my C# code, after I have connection to database to my database and I make a query to get SectionDatatablewhich is XML format in my database, UserDefinedSectionData. I need to convert the 'SectionDatatable' in XML Datatype and convert it into DataSet, how can I do it. I have stuck for 1 day, the following is my code. SqlConnectionStringBuilder csb = new SqlConnectionStringBuilder(); csb.DataSource = @

C# SqlConnection Querying Temporal tables

一曲冷凌霜 提交于 2019-12-11 12:46:49
问题 I have a temporal table Employee with EmployeeHistory as its history table. In C#, I am using SqlConnection to query the data from SQL Server for the entire history of an employee. var data = Conn.ExecuteReader("select * from Employee e FOR SYSTEM_TIME ALL WHERE e.Id=15"); This throws the error: Incorrect syntax near FOR So, how do we query history data for a temporal table in C# using SqlConnection ? 回答1: Problem is you are using table alias e and so the error. Don't think you can use table

Does using (var connection = new SqlConnection(“ConnectionString”)) still close/dispose the connection on error?

删除回忆录丶 提交于 2019-12-11 07:40:50
问题 I have the following code try { using (var connection = new SqlConnection(Utils.ConnectionString)) { connection.Open(); using (var cmd = new SqlCommand("StoredProcedure", connection)) { cmd.CommandType = System.Data.CommandType.StoredProcedure; var sqlParam = new SqlParameter("id_document", idDocument); cmd.Parameters.Add(sqlParam); int result = cmd.ExecuteNonQuery(); if (result != -1) return "something"; //do something here return "something else"; } } //do something } catch (SqlException ex

how to close a sqlconnection in asp.net

﹥>﹥吖頭↗ 提交于 2019-12-11 07:28:23
问题 i would like to know if there's something wrong in this asp.net code: mydatareader = mycmd.executeReader() if myDataReader.HasRow then // Do something end if myConnection.Close() If i avoid to call a "MyDataReader.Close()" does the connection close anyway ? I ask this because i'm assuming that if call a "MyConn.Close" it automatically close the associated datareader... or am i wrong ? Thanks 回答1: You have to close your reader instead of closing the connection. Have a look here: http://msdn

Having problems connecting to SQL Server in C#

╄→尐↘猪︶ㄣ 提交于 2019-12-11 06:08:11
问题 I am trying to connect to a SQL Server. I am trying to use the SqlConnection object in C#, I've tried putting a domain before my username and I've tried with and without the portnumber SqlConnection myConnection = new SqlConnection("user id=username;" + "password=xxxxx;" + "server=ipaddress:portnumber;" + "Trusted_Connection=yes;" + "database=databaseName; " + "connection timeout=30"); try { myConnection.Open(); } catch(Exception ex) { } I don't get any error message, it just hangs at

how to bind datatable to webgrid using MVC?

亡梦爱人 提交于 2019-12-11 03:51:08
问题 This is my first post. help me. how to bind datatable to webgrid? My code: SqlConnection con = new SqlConnection(CS); SqlCommand cmd = new SqlCommand("select * from candidate", con); SqlDataAdapter da = new SqlDataAdapter(cmd); DataTable dt = new DataTable(); da.Fill(dt); return View(dt); I want to bind datatable to webgrid..help me... 回答1: This is best solution I found :) hope it can help you: SqlConnection con = new SqlConnection(CS); SqlCommand cmd = new SqlCommand("select * from candidate