polachan

Dear All

Please help me urgent. I am beginner in C#. I created a Application configuration(app.config) with the following code

configuration>

<appSettings>

<add key="DSN" value="Provider=SQLOLEDB;data source=.\SQLEXPRESS;integrated security=SSPI;Initital Catalog=DailyAccount"/>

</appSettings>

</configuration>

in the DailyAccount database have one table journal .

After that I create a class like following

public class Journal

{

public static Journal GetQuestion(System.Int32 Id)

{

String ConnectionString = System.Configuration.ConfigurationManager.AppSettings["DSN"];

String query = "select * from Journal where Id = " + Id;

DataTable Dt = DataManager.ExecuteQuery(ConnectionString, query, "Journal ");

if (Dt.Rows.Count == 0)

{

return null;

}

return new Journal (Dt.Rows[0]);

}

}

The executeQuery is as follows

public class DataManager

{

public static DataTable ExecuteQuery(string ConnectionString, string query, string tableName)

{

try

{

OleDbConnection myConnection = new OleDbConnection(ConnectionString);

OleDbDataAdapter myAdapter = new OleDbDataAdapter(query, myConnection);

DataSet ds = new DataSet();

myAdapter.Fill(ds, tableName);

ds.Tables[0].TableName = tableName;

return ds.Tables[0];

}

catch (Exception ex)

{

string message = ex.Message;

throw ex;

}

}

But after executing the SQL the following exception is fired

Invalid object name . Please help me




Re: Visual C# General Invalid object name

Zamial

Hmm on a brief scan you pass an extra space at the end of Journal but that sounds trivial Big Smile

Run the query on the db

Select * from Journal and see if it works. If it does prepend the user anyway like dbo.Journal.

I believe the object is not owned by username you are using to log in and as such it cannot be found.

Also make sure the ID column on the DB is an int as well. I'm sure it is.





Re: Visual C# General Invalid object name

In Love With Dotnet

Hi,

Error description "Invalid object name" means object is not found in database. Your database connectiol looks successful otherwise you would have had other error. Copy this query in try to run in sql itself. Your query here would be

select * from Journal where Id = 1

I have just put 1. You replace this value with one of the valid after checkin ID column's value from journal table of your database. If that query fails then analyze the error and let me know. If this query works then you check your access. I dont think that would be an issue. Try out this and let me know. We will get rid of this.

Hope this will help






Re: Visual C# General Invalid object name

polachan

Very much thank you in first.

I executed the query in SQLEXPRESS , that is working . But in the program it is showing error . While I am debugging the in connection the following message is shown in connection

ServerVersion = 'myConnection.ServerVersion' threw an exception of type 'System.InvalidOperationException'

OleDbConnection myConnection = new OleDbConnection(ConnectionString);

When I am debugging myConnection the above message got






Re: Visual C# General Invalid object name

In Love With Dotnet

Okay. You may need to check out if database you are using is password protected or not. You can try one option to generate perfect connection string. In aspx page, select toolbox on right side and select "SqlDataSource" and click on "Configure Data Source Option". Keep providing details and check at the end for "Test Connection". After is successfully done, copy connection string which you can see at the bottom part and replace it with existing one. Notice the difference if it is.

Something is wrong with connection string only as it is not able to make connection with database. Try this out.






Re: Visual C# General Invalid object name

polachan

Thank You

Data Source=PC252073203920\SQLEXPRESS;Initial Catalog=DailyAccount;Integrated Security=True. This was the connection string given from there and I copied this still error occure






Re: Visual C# General Invalid object name

In Love With Dotnet

Hi,

You connect to Access for a while n check your code, should work. Create dummy DB n table in access. If that works fine then looks like rights problem with SQLExpress. Give it a try.






Re: Visual C# General Invalid object name

In Love With Dotnet

Hi Dude,

Did you get any luck on this






Re: Visual C# General Invalid object name

polachan

Dear All

I given the connection like the following way

<add key="DSN" value="Provider=SQLOLEDB;data source=PC252073203920\SQLEXPRESS;integrated security=SSPI;database=DailyAccounts"/>

After that it is working..

Thanks ...






Re: Visual C# General Invalid object name

In Love With Dotnet

Thats great. I can observe minor difference! Please mark this one as resolved. If my post was helpful, please mark it YES above.

Happy Programming.






Re: Visual C# General Invalid object name

Zamial

Well quite clearly the fact that in the first he points at database DailyAccount and in the second he points at DailyAccounts the problem is quite clear




Re: Visual C# General Invalid object name

polachan

No Zamiel Database is DailyAccount itself . Thats my typing problem

Regards






Re: Visual C# General Invalid object name

In Love With Dotnet

Difference is name of DB was initially specified in initial catalog which is now in DB. This happens often when you try to build connection string often, may miss sometimes and does the old way. You can probably take out your PC name out now as there is .\

Again, request you to mark this one as resolve to let community know this is not to look into.

Cheers