a SQL2005 which is alone and A web server is under domain. I am using C#, it can open the connection, but it prompted error on talbe not found when excute the sql.
is the SQL2005 must join in same domain even use the SQL authorization?
No, definitely not. Using the right connection string to connect to the right database should work. Get your connection string at www.connectionstrings.com. Perhpas you are not connected to the right instance of your SQL Server ?
HTH, Jens suessmeyer,
http://www.sqlserver2005.de
|||I have a Database named "SmartEngine060503BGCA"
I can use the Query Analyzer with SA to use the "SmartEngine060503BGCA"
I don't why I cannot use it in C#
I found that it only able to use the table in Master Database, e.g. sysfiles
//String dsn="Server=bgca-mosaic;Database=SmartEngine060503BGCA;User ID=sa;Password=sa;Trusted_Connection=False";
String dsn = "Data Source=bgca-mosaic;User Id=sa;Password=sa;Initial Catalog=SmartEngine060503BGCA";
SqlConnection sConn = new SqlConnection(dsn);
sConn.Open();
string ssql = "select * from mosaic";
SqlCommand sc = sConn.CreateCommand();
sc.CommandText = ssql;
SqlDataReader sr = sc.ExecuteReader();
sConn.Close();
--ERROR-
[SqlException (0x80131904): Invalid object name 'mosaic'.]
System.Data.SqlClient.SqlConnection.OnError(SqlException exception, Boolean breakConnection) +786210
System.Data.SqlClient.SqlInternalConnection.OnError(SqlException exception, Boolean breakConnection) +684822
System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj) +207
System.Data.SqlClient.TdsParser.Run(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj) +1751
System.Data.SqlClient.SqlDataReader.ConsumeMetaData() +37
System.Data.SqlClient.SqlDataReader.get_MetaData() +58
System.Data.SqlClient.SqlCommand.FinishExecuteReader(SqlDataReader ds, RunBehavior runBehavior, String resetOptionsString) +213
System.Data.SqlClient.SqlCommand.RunExecuteReaderTds(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, Boolean async) +570
System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method, DbAsyncResult result) +134
System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method) +32
System.Data.SqlClient.SqlCommand.ExecuteReader(CommandBehavior behavior, String method) +122
System.Data.SqlClient.SqlCommand.ExecuteReader() +84
Remember that the prefix is a schema in SQL Server 2005, not a user. What he means is try to figure about the Schema where the table is stored, the default one for the sa is dbo, if its not dbo, you have to prefix it before the objectname like SchemaName.ObjectName.
The information for that can be queried from the (SELECT * FROM) INFORMATION_SCHEMA.Tables View.
HTH, Jens Suessmeyer.
http://www.sqlserver2005.de
-
No comments:
Post a Comment