Connecting Tech Pros Worldwide Forums | Help | Site Map

Database creation in SQL 2005 from C# - works from one computer, not the other

Newbie
 
Join Date: Aug 2007
Location: VA
Posts: 6
#1: Aug 17 '09
Was hoping someone could give me some things to check here - I'm trying to figure this one out.

I've got a SQL connection string in an INI file, it is read into my C# .NET console app and connects to the database fine from my workstation. It processes the SqlCommand statements I use to drop the table (if it exists) and re-create it, and does an Insert statement to fill one row, and quits. This all works fine from my workstation (running XP) when ran on the command line.

When I copy it over to our IIS server (running W2K3) and run it the same way, using the same INI file, same DB connection string to hit the same SQL server it was able to create the DB on before, it does not work. Any thoughts on why this might happen? I'm logged in as me on both my workstation and the server, and my account has DB creation and admin rights on the SQL server. I have another console app on the IIS server that can hit that SQL server fine. At a loss here.

Thanks,
Tom

tlhintoq's Avatar
Moderator
 
Join Date: Mar 2008
Location: Arizona, USA
Posts: 1,782
#2: Aug 17 '09

re: Database creation in SQL 2005 from C# - works from one computer, not the other


Quote:
it does not work.
A bit vague.

Logging. It's hard to create *too much* logging in a program. Give your program a ton of logging. I'll bet that most of your methods do a "console.writeline()" from when you were building and debugging it, so you could see where something worked and didn't. Those things are a good start on what to write to a log file.

I'd bet it will come down to something simple and easy to overlook like an extra '\' in a path etc. But it will be hard to find unless you log attempts and responses:

12:31.123: Attempt to connect to "http:\\mydatabase.sql"
12:31.666: Connection failed: "wrong password"
Newbie
 
Join Date: Aug 2007
Location: VA
Posts: 6
#3: Aug 18 '09

re: Database creation in SQL 2005 from C# - works from one computer, not the other


Thanks for the quick response. Yeah, I agree that was a little vague.

What I meant to say is that my program seemed to go through all of the motions, but not create the database or tables. I thought my "Console.WriteLine" statements completed as they should, but it turned out I did need more in there - I had them before and after the call to the class that contains the SqlCommands that create the tables, before, and these would write fine. So I put them right after the ExecuteNonQuery statements on my SqlCommands that created the tables, and these DID NOT write. I have it write the error from any SqlException that could come up to the Event Log, but nothing gets written. What would cause the tables not to write, but no exception to be raised?

Thanks,
Tom
tlhintoq's Avatar
Moderator
 
Join Date: Mar 2008
Location: Arizona, USA
Posts: 1,782
#4: Aug 18 '09

re: Database creation in SQL 2005 from C# - works from one computer, not the other


Quote:
So I put them right after the ExecuteNonQuery statements on my SqlCommands that created the tables, and these DID NOT write.
I'm going to guess some exception occured and the code aborted, so it didn't make it to the line writing the error condition.

Quote:
What would cause the tables not to write, but no exception to be raised?
Invalid path
Invalid command
Newbie
 
Join Date: Aug 2007
Location: VA
Posts: 6
#5: Aug 19 '09

re: Database creation in SQL 2005 from C# - works from one computer, not the other


The ExecuteNonQuery statements are inside of a try...catch, so if there was an exception raised, the event would be logged since the EventLog routine is inside of my catch (wouldn't it?). I know the SqlCommands are valid since they will write the tables when the app is run from my workstation. All I'm doing is moving the app from my workstation to a server - I keep everything the same (connection string in the INI file, other INI settings). What could cause it not to perform the table creation SqlCommands from the server when it can do them from the workstation? Are there client-side OS settings that should be re-configured or something?

Thanks,
Tom
Reply

Tags
connection string, database, ms sql 2005