Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
Author |
Topic |
ward0093
Starting Member
15 Posts |
Posted - 2006-03-01 : 16:48:52
|
I want to check to see if a database exists in SQL Server 2005 Express... using VB.NET (or C#)... Can not use the SQLConnection Object... because I get a Failed Login Attempt... regardless if the DB does not exist or if it is because the User Login is incorrectIs there some way to check to see if the Database exists (is attached) to the SQL Server 2005 Express Engine?ward0093 |
|
mikewa
Microsoft SQL Server Product Team
84 Posts |
Posted - 2006-03-01 : 17:11:13
|
You'll need to connect to SQL Express in order to determine if a database is attached, so you should focus on solving that problem first. Could you post the code that is failing along with the exact error message you are receiving?Also, see if you can connect to the database using SQLCmd, from a command prompt type:SQLCmd -E -S .\sqlexpress(this assumes you're using Windows Auth and the default instance name)If you can connect, you should be left at a prompt that reads "1>", if not you'll get an error, which I would also like you to provide the exact message back to this forum.Regards,Mike WachalSQL ExpressThis posting is provided "AS IS" with no warranties, and confers no rights.Use of included script samples are subject to the terms specified athttp://www.microsoft.com/info/cpyright.htm |
|
|
ward0093
Starting Member
15 Posts |
Posted - 2006-03-01 : 17:37:14
|
I am not getting any error message... I am designing the Initialization part of our Windows Application.... and wanted to write some error portions to check to see if the database even exists...any idea's?ward0093 |
|
|
mikewa
Microsoft SQL Server Product Team
84 Posts |
Posted - 2006-03-01 : 23:11:52
|
How do you know that you're getting a failed logon if you're not getting an error, or at least looking at an error log? If you're having problems connecting, I can help figure out why, if you're able to connect and just need help coding the way to check for a database, I'm not much help as I don't know much VB.That said, you'd need to use the Command object and pass a T-SQL statement that looks for the database you're interested in. You'd need to use the SQLConnection object to connect in order to use a command. The T-SQL would be something like:USE masterSELECT Count(*) FROM sys.databases WHERE [name]='foo' Replace 'foo' with your database. If it's there it will return 1, otherwise it will return 0. A good place to get more help with writing VB.NET code against SQL (any Edition) is in the MSDN VS Forums. There is a forum specifically for ADO.NET coding.Regards,Mike WachalSQL ExpressThis posting is provided "AS IS" with no warranties, and confers no rights.Use of included script samples are subject to the terms specified athttp://www.microsoft.com/info/cpyright.htm |
|
|
|
|
|
|
|