I'm writing an app in C# with a MS Access backed (.accdb). I made the call (on advisement) that SQL Server was a much better idea for my system, thus I spent the last 8 hrs re-coding to SQL Server.
As a background;
Changed all OLEDB connection, command etc etc to Sql
Fixed all parameters and variables from ? to #value
Fixed all SQL string errors
Now all my forms are working with the exception of the ones using BINDING done by Visual Studio 'wizard' (if that's what it's called).
I have 5 forms which are filled using
this.tbljobTableAdapter.Fill(this.websterdbDataSet.tbljob);
They are all using a DataGridView depending upon that info.
On "Save and Close", this code runs:
this.Validate();
this.tbluserBindingSource.EndEdit();
this.tableAdapterManager.UpdateAll(this.websterdbDataSet);
_owner.PerformRefresh();
this.Close();
this.Dispose();
This works 100% still with my .ACCDB version (I'm checking from a backup) but not now that it is SQL Server.
If I press Save and Close and haven't changed ANYTHING, it closes, but if I change any field at all it fails with this (from my log):
Data Time:21/08/2017 12:12:20 AM
Exception Name:Incorrect syntax near '`'.
Event Name:System.Windows.Forms.MouseEventArgs
Control Name:BtnSave
Error Line No.:86
Form Name:frmjoblist
Any ideas how I can further debug this?
I thought it was something I did when adding Try and Catch to all my sections, but in the end this is happening to the specific 5 forms that I used the wizard instead of manually creating, binding and writing SQL update strings for.
Thanks for any advice/direction.
GAngel
So the deisgner was still all in OLEDB, therefore I ended up deleting the dataset and recreating using the correct connection which rebuilt the designer in SQL
Related
I apologize in advanced as I see many similar questions however none that fit my distinct case.
I am making a database for my employers using SQL (converted from access) and visual studio 2017 c#. The newest issue I have come across is receiving an
System.InvalidOperationException: 'ExecuteNonQuery: CommandText property has not been initialized'
error when trying to delete an object from a datatable and then try to save it. I can add and alter pieces then save it with no error. I have not changed any of the code regarding saving back to the SQL server that visual studio auto-generated for me.
Snooping around The piece of code that it uses to save is
this.Validate();
this.clientsBindingSource.EndEdit();
this.tableAdapterManager.UpdateAll(this.clientEmployerDataSet);
I can not find where it keeps the delete command however so I can't see if something is misaligned there.
So I found the issue on line 5764 of the dataset designer, the line just says
this._adapter.DeleteCommand.CommandText = "";
instead of having the proper SQL delete command put in.
Edit: Not as solved as I would like as it turns out. I have no clue what the 'while' condition should be (after finding out that DELETE FROM does work...too well and deletes everything (that's why we have backups)).
So, I'm mantaining a software an ex co-worker did.
He uses an xsd to create TableAdapters for his reports and other stuff.
The thing is, I need to add a new TableAdapter and I get the aforementioned error. It also says the dread "A network-related or instance-specific error occurred while establishing a connection to SQL Server."
I am at loss here and I don't know what to do. Here are the facts:
I have 2 connection strings, one for the production environment and one for the development environment (my computer).
When I go to settings and then the edit window of the connection string, I hit "test connection" and it says it works fine.
Both SQL Server 2008R2 and Visual Studio 2010 are on the same machine, my machine.
I do not have a named instance.
I right click on the xsd design view and click "Add -> TableAdapter" and use the local connection string (the one I already tested and worked)
I click "Use existing stored procedures" and then hit [Next]. Then I am able to pick a stored procedure for the Select section and I can see the columns.
I click finish, the system locks for a while and then I get the error.
Named Pipes, TCP/IP are enabled in SQL Server configuration.
I'm kinda lost and I already wasted 2 days on this. I have tried what little I know and nothings works. I hope I can find help within your wisdom.
Sorry for the long post but I wanted to provide as much info as I could in one single shot.
OK, After some trial and error, I found the solution. At least, I made it work on my environment.
What #Rusland said, made me think and I searched for another Settings file. It did not exist. I decided then to erase the connection strings and the Settings file to see if the project compiled. As expected, it threw a ton of errors.
So, it was not the file.
I decided to add one by one the connection strings and test as I added them. The first one that I added, was the connection string used in development (localConStr). The configuration of the table adapter was as shown in the first image. As you can see, localConStr is selected (as has always been) only this time, having only one connection string I received an error, a different error than before. The one in the second image.
How could it be possible for the TableAdapter to ask for that Connection String if there were no refferences to it? I deleted it and the Connection property of my table adapter was set to the localConStr. So... I did what any desperate man would do: CTRL+F and find all refferences to rptTbl_loansAgingTableAdapter. My only reasoning was that somewhere in the code, the connection string was probably hardcoded by my predecessor. One thing worth mentioning: I specifically used "loansAgingTableAdapter" as the search criteria because that's the one TableAdapter I was trying to modify in the first instance.
After some minutes, I was navigating the XSD at code level (it's just an XML) and to my surprise, I found an element named Connection and there was not one but TWO!. Just to make things clear, this file has been untouched by me till today (I mean, I did not touch it by hand, any changes had been made by the IDE)
The two connection strings were:
<Connection AppSettingsObjectName="Settings" AppSettingsPropertyName="localConStr"...
and
<Connection AppSettingsObjectName="Settings" AppSettingsPropertyName="loanConStr" ...
Yes, I know they look very alike, but notice they are local and loan. I decided to delete the second one (loanConStr) since it was not in my Settings file anymore (loanConStr was the original connection string left by my predecessor, localConStr was created by me so that I could switch connection strings in runtime instead of modifying the connection string and recompile every time I had to make a change and deploy again).
After that, I made sure all the DataTables in my DataSet used the same connection string (localConStr) and recompiled. I then tried the things that were giving me troubles:
First: I created a new DataTable: the action was successful
Second: I modified an existing DataTable: success again
Last, but not least, I tried to execute the report. I ran the app and went to the report and success! Apparently, my problem is solved.
What had happened? I am not sure, but if I had to guess, I would say that the TableAdapter was trying to use a connection string that pointed to a server that did not exist in my network (my client's server) so, every time I tried to configure it or change anything, Visual Studio was unable to contact that server and that's why I gor the connection error.
Why was the TableAdapter trying to use that connection string when the local connection string was explicitly specified? I don't know, but leavin IN THE XSD only one connection string was my solution.
As a side note, you might ask "But Compa, what will happen when the user wants to run a report that uses the localConStr?" Simple, I change the connection string at runtime when the report window is opened with the one being used by the whole app.
Sorry for the long post, and if you want a TL;DR version:
Go to your xds dataset file, delete any unwanted connection strings and then go to design view and make sure all your TableAdapters use the only ConnectionString specified in your xsd
It looks like you're seeing the database just fine. (Thus you get a list of stored procedures).
Try the rights on the procedure itself.
GRANT EXECUTE on [dbo].[rpt_loansAging] to [TheSqlAuthenticationUserNameWeCannotSeeInTheScreenShot]
APPPEND
Since you've tried everything else, try opening up a new VS project (Same version of VS and Target Framework) and try adding a TableAdapter in the same way.
If that works, then you got voodoo going on. You could delete and recreate them in the original project.
Every blue moon, something goes awry with Visual Studio, ESPECIALLY projects that started out as VS2003, were upgraded to VS2005, maybe upgraded to VS2010 (whatever combination).
I had a project that I upgraded from VS2003 to VS2005, and it built fine on my computer. On the build machine, it started failing........No idea what it was.
I ended up seeing some small anomaly in the "By Project" references. I simply removed all "By Project" references (within the .sln solution) ... and re-added the "By Project" references, and it fixed everything.
Go figure.
I am using Visual Studio C# 2008 and SQL Server Express. i got a question
i have the following data on my database
and then, i want to insert a new data
after that, i have to make sure that the entered data is saved on my database
it was there, the data was entered succesfully ! but then, when i take a look at my database table
the entered data was not saved permanently. i need to make the entered data saved permanently. how do i resolve this ?
thanks !
You are using the User Instances = true + AttachDbFileName "feature." When you use this "feature" each application you use will open a different copy of the original MDF file. So your C# app opens one copy, you insert a row, but this is never seen in the copy that is open in SSMS / Visual Studio or wherever else you might review the data.
To fix this, STOP USING THIS "FEATURE".
Create/attach your database to a proper instance of SQL Server, and point to it from your app and SSMS / Visual Studio by referencing the server and the logical database name, not the path to an MDF file.
You'll notice I called this a "feature" - in quotes - multiple times. This is because it is not a feature and has caused countless, countless users before you to become absolutely confused about why their inserts and updates "don't work"...
I have one store procedure in my database, it makes many things and print results when i run it on sqlserver management studio (ssms), for example:
exporting table abc...
exporting table def...
deleting table temp...
My program has to run the store procedure and show the output anywhere (maybe creating a log file), such as ssms does (it shows output in the messages tab). I have to show exactly the same ssms shows. How can I do this?? sqlcmd, ado.net?? I see this question
How to run sql from a .net application against sqlserver and get output like with SQL Management Studio?
but, answer is not clear... Help!!
If you want to capture warning and information messages, you will want to create a SqlInfoMessageEventHandler delegate to handle the SqlConnection.InfoMessage event. See references below for details.
http://msdn.microsoft.com/en-us/library/system.data.sqlclient.sqlconnection.infomessage.aspx
http://msdn.microsoft.com/en-us/library/system.data.sqlclient.sqlinfomessageeventhandler.aspx
In some projects, but not all, when I open a designer for the first time (either WinForms or typed dataset) Visual Studio thrashes the disk for up to 30 minutes while freezing (this appears to be reads and writes with between 100 and 140 pages\sec).
Once it has done it the first time for a project, it's fine opening other projects until I close and re-open VS where it will freeze/thrash again the first time I open a designer.
Does anyone else see this, what the hell is it doing, and is there anything I can do to stop it?
It sounds like you are either running short on RAM and opening a designer puts it over the top or your hard disk needs to be defragmented.
It could be registry fragmentation too. Try pagedefrag.
OK, so it looks like it was defunct database connections in the Server Explorer tab:
A database on our test server was removed without my knowledge, but my project still had a data connection set up for it. It seems that whenever a table adapter is initialised in the designer, VS tries to connect to all the databases in the data connections list causing issues if the database does not exist. It even tries to connect to data connections that are not used by the current table adapter.
Some of our WinForms were badly written (naughy devs!) and were loading data in the constructors without checking for 'DesignMode' - these have been repaired.
Herbie