VB to C# SQL Server conversion error
-
Can anyone see what I'm doing wrong here? I have translated some (simple) VB code to C# but the original works while the C# doesn't. Here it is: VB Code: (works)
Dim oDR as System.Data.SQLClient.SQLDataReader Dim oCom As System.Data.SQLClient.SqlCommand Dim oConn as System.Data.SQLClient.SQLConnection try oConn = New System.Data.SQLClient.SQLConnection ("server=MACH2\vsdotnet; initial catalog=tablexxx; uid=test2; pwd=test2") oConn.Open() ...
C# Code: (Gives error: SQL Server does not exist or access denied)System.Data.SqlClient.SqlDataReader oDR; System.Data.SqlClient.SqlCommand oCom; System.Data.SqlClient.SqlConnection oConn; try { oConn = new System.Data.SqlClient.SqlConnection("server=MACH2\vsdotnet; initial catalog=tablexxx; uid=test2; pwd=test2"); oConn.Open(); ...
Any ideas? -
Can anyone see what I'm doing wrong here? I have translated some (simple) VB code to C# but the original works while the C# doesn't. Here it is: VB Code: (works)
Dim oDR as System.Data.SQLClient.SQLDataReader Dim oCom As System.Data.SQLClient.SqlCommand Dim oConn as System.Data.SQLClient.SQLConnection try oConn = New System.Data.SQLClient.SQLConnection ("server=MACH2\vsdotnet; initial catalog=tablexxx; uid=test2; pwd=test2") oConn.Open() ...
C# Code: (Gives error: SQL Server does not exist or access denied)System.Data.SqlClient.SqlDataReader oDR; System.Data.SqlClient.SqlCommand oCom; System.Data.SqlClient.SqlConnection oConn; try { oConn = new System.Data.SqlClient.SqlConnection("server=MACH2\vsdotnet; initial catalog=tablexxx; uid=test2; pwd=test2"); oConn.Open(); ...
Any ideas?try this: server=MACH2\vsdotnet;user id=test2;password=test2;database=tablexxx Good luck Al
-
try this: server=MACH2\vsdotnet;user id=test2;password=test2;database=tablexxx Good luck Al
Thanks for the idea Al. I've tried that but no luck - unfortunately. Exactly the same error. Thanks again for taking the time to look at the problem!
-
Thanks for the idea Al. I've tried that but no luck - unfortunately. Exactly the same error. Thanks again for taking the time to look at the problem!
No allow to thank me until we find the problem. Please can you test this for me? SqlConnection myConnection = new SqlConnection(YOURCONNECTIONSTRING); SqlCommand myCommand = new SqlCommand(sQuery, myConnection); myCommand.CommandTimeout = 120; // 60 Seconds Timeout myConnection.Open(); SqlDataReader result = myCommand.ExecuteReader(CommandBehavior.CloseConnection);
-
No allow to thank me until we find the problem. Please can you test this for me? SqlConnection myConnection = new SqlConnection(YOURCONNECTIONSTRING); SqlCommand myCommand = new SqlCommand(sQuery, myConnection); myCommand.CommandTimeout = 120; // 60 Seconds Timeout myConnection.Open(); SqlDataReader result = myCommand.ExecuteReader(CommandBehavior.CloseConnection);
That didn't help either Al - exactly the same error. I've just had a thought. Remember with C/C++ you can choose the calling parameter convention and the order in which to push and pop parameters off the stack? i.e. PASCAL or CDECL or something like that? Well I'm just wondering if this is the problem now... What I'm doing to test this is switching between a testCS.aspx page as the start page and a testVB.aspx start page. Does the project need to know a calling convention or some other global setting to make one work? Or can you just mix and match VB and C# in a project. I'm aware that you can't mix C# and VB in a file but I was under the impression that an ASPX file can be in either or and you can mix the files together in a project. Thanks again for your help.
-
That didn't help either Al - exactly the same error. I've just had a thought. Remember with C/C++ you can choose the calling parameter convention and the order in which to push and pop parameters off the stack? i.e. PASCAL or CDECL or something like that? Well I'm just wondering if this is the problem now... What I'm doing to test this is switching between a testCS.aspx page as the start page and a testVB.aspx start page. Does the project need to know a calling convention or some other global setting to make one work? Or can you just mix and match VB and C# in a project. I'm aware that you can't mix C# and VB in a file but I was under the impression that an ASPX file can be in either or and you can mix the files together in a project. Thanks again for your help.
:doh: NO!! If you got a project in C# you cannot add a Page is aspx.vb!!! You can only have a C# project or a VB project. Al
-
:doh: NO!! If you got a project in C# you cannot add a Page is aspx.vb!!! You can only have a C# project or a VB project. Al
The VB and C# code is working side by side in the same project because it is in an ASPX file and not in the code behind file. In fact, when I initially tried to do this conversion from VB to C# there was no code behind file. I've subsequently tried all sorts of combinations: I've completely removed the ASPX file holding the VB code. I've used the C# code only in the aspx file (i.e. inline) and also in a code behind file but same results: SQL Server error with C# but not when using VB. As you can see from my initial post, the code is very simple and straight forward and should translate without a problem.
-
The VB and C# code is working side by side in the same project because it is in an ASPX file and not in the code behind file. In fact, when I initially tried to do this conversion from VB to C# there was no code behind file. I've subsequently tried all sorts of combinations: I've completely removed the ASPX file holding the VB code. I've used the C# code only in the aspx file (i.e. inline) and also in a code behind file but same results: SQL Server error with C# but not when using VB. As you can see from my initial post, the code is very simple and straight forward and should translate without a problem.
If you put the code is the ASPX page instead of the code behind you are correct should compile. Now, I can't belive that does not work. Any chance you can send me the complete project to albert@autojockey.com? Cheers Al
-
If you put the code is the ASPX page instead of the code behind you are correct should compile. Now, I can't belive that does not work. Any chance you can send me the complete project to albert@autojockey.com? Cheers Al
The email is on its way. Thanks Al.
-
The email is on its way. Thanks Al.
We will figure out. Sometimes is late at night and something that we over looked is the problem, but we need another sets of eyes to figure it out. Cheers Al
-
The email is on its way. Thanks Al.
Think I got it, intead of calling the public function Page_Data() put the whole thing in the page ASPX so ... I did not compile it yet and test it, I would do it if this does not work.
<% System.Data.SqlClient.SqlDataReader oDR; System.Data.SqlClient.SqlCommand oCom; System.Data.SqlClient.SqlConnection oConn; //string connString = "server=MACH2\vsdotnet; initial catalog=chatlogs; uid=test2; pwd=test2"; string connString = "server=MACH2\vsdotnet; Database=chatlogs; User ID=test2; Password=test2"; oConn = new System.Data.SqlClient.SqlConnection(connString); try { oConn.Open(); oCom = new System.Data.SqlClient.SqlCommand(); oCom.Connection = oConn; oCom.CommandText = "SELECT * FROM cl_channel"; oDR = oCom.ExecuteReader(); while(oDR.Read()) { Response.Write(oDR["network"] + ", " + oDR["channel"]); Response.Write(" "); } oConn.Close(); } catch(Exception err) { Response.Write("Error: " + err.Message); } finally { oDR = null; oCom = null; oConn.Close(); oConn = null; } %>
-
Think I got it, intead of calling the public function Page_Data() put the whole thing in the page ASPX so ... I did not compile it yet and test it, I would do it if this does not work.
<% System.Data.SqlClient.SqlDataReader oDR; System.Data.SqlClient.SqlCommand oCom; System.Data.SqlClient.SqlConnection oConn; //string connString = "server=MACH2\vsdotnet; initial catalog=chatlogs; uid=test2; pwd=test2"; string connString = "server=MACH2\vsdotnet; Database=chatlogs; User ID=test2; Password=test2"; oConn = new System.Data.SqlClient.SqlConnection(connString); try { oConn.Open(); oCom = new System.Data.SqlClient.SqlCommand(); oCom.Connection = oConn; oCom.CommandText = "SELECT * FROM cl_channel"; oDR = oCom.ExecuteReader(); while(oDR.Read()) { Response.Write(oDR["network"] + ", " + oDR["channel"]); Response.Write(" "); } oConn.Close(); } catch(Exception err) { Response.Write("Error: " + err.Message); } finally { oDR = null; oCom = null; oConn.Close(); oConn = null; } %>
I tried that before Al. That's how it was originally when it didn't work. Only when it didn't work did I move it into the code behind page to see if that would make it work. But I will try again anyway and report back...
-
I tried that before Al. That's how it was originally when it didn't work. Only when it didn't work did I move it into the code behind page to see if that would make it work. But I will try again anyway and report back...
Don't try again, I'll stop being lazy and test your app tomorrow morning. I'll report the results to you. I am just being lazy. I started working this morning at 7:30 and now at 9:30 PM I am still in the computer, so I cannot take more code :wtf: However tomorrow morning I'll be fresh again to help you with. Last thought did you try to put the IP address instead of the name? localhost if its the same computer Talk to you tomorrow morning Al
-
Don't try again, I'll stop being lazy and test your app tomorrow morning. I'll report the results to you. I am just being lazy. I started working this morning at 7:30 and now at 9:30 PM I am still in the computer, so I cannot take more code :wtf: However tomorrow morning I'll be fresh again to help you with. Last thought did you try to put the IP address instead of the name? localhost if its the same computer Talk to you tomorrow morning Al
I haven't tried that Al but will do - I'm about to crash as well. Thanks for all your help today. Perhaps tomorrow we'll crack it :)
-
Can anyone see what I'm doing wrong here? I have translated some (simple) VB code to C# but the original works while the C# doesn't. Here it is: VB Code: (works)
Dim oDR as System.Data.SQLClient.SQLDataReader Dim oCom As System.Data.SQLClient.SqlCommand Dim oConn as System.Data.SQLClient.SQLConnection try oConn = New System.Data.SQLClient.SQLConnection ("server=MACH2\vsdotnet; initial catalog=tablexxx; uid=test2; pwd=test2") oConn.Open() ...
C# Code: (Gives error: SQL Server does not exist or access denied)System.Data.SqlClient.SqlDataReader oDR; System.Data.SqlClient.SqlCommand oCom; System.Data.SqlClient.SqlConnection oConn; try { oConn = new System.Data.SqlClient.SqlConnection("server=MACH2\vsdotnet; initial catalog=tablexxx; uid=test2; pwd=test2"); oConn.Open(); ...
Any ideas?I haven't followed all this thread... but just a small check... in C#, the '\' character has to be written as '\\' in a string constant right? so for example, if your server name is MACH2\vsdotnet, your string connection for C# should be oConn = new System.Data.SqlClient.SqlConnection("server=
**MACH2\\vsdotnet**
; initial catalog=tablexxx; uid=test2; pwd=test2"); Just wondering, because porting from one programming language to another shouldn't make such a problem :doh:. daniero -
I haven't followed all this thread... but just a small check... in C#, the '\' character has to be written as '\\' in a string constant right? so for example, if your server name is MACH2\vsdotnet, your string connection for C# should be oConn = new System.Data.SqlClient.SqlConnection("server=
**MACH2\\vsdotnet**
; initial catalog=tablexxx; uid=test2; pwd=test2"); Just wondering, because porting from one programming language to another shouldn't make such a problem :doh:. danierodaniero - you are a genius. I knew it was going to be something simple like that that I'd overlooked and another pair of eyes would spot. That fixed the problem - thanks again daniero. Also thanks to Al for all the time and effort he put in helping me here. The solution was so simple it alluded us for an entire day.
-
daniero - you are a genius. I knew it was going to be something simple like that that I'd overlooked and another pair of eyes would spot. That fixed the problem - thanks again daniero. Also thanks to Al for all the time and effort he put in helping me here. The solution was so simple it alluded us for an entire day.
:doh: and :doh: again We both need to catch up in our sleep. Thanksgiving is tomorrow, can't wait to get off the computer Cheers Al
-
daniero - you are a genius. I knew it was going to be something simple like that that I'd overlooked and another pair of eyes would spot. That fixed the problem - thanks again daniero. Also thanks to Al for all the time and effort he put in helping me here. The solution was so simple it alluded us for an entire day.
I'm glad I could help :). Those kind of things always get on my nerves as well :doh:, I always try to think of the easiest mistakes. daniero