I am trying to run a query, like the following:
SqlCommand putuser = new SqlCommand("INSERT INTO MainDB(NumberofEmployees) VALUES(4)", cn);
putuser.ExecuteNonQuery();
I get an Invalid object name error for the table named MainDB. I have checked the following:
I am using Forms authentication. How do I make it so that anyone who access the application can make this insert to the Database. The insert is initially occurring after a user is created.
Are you using a connection string with Windows authentication or SQL Server authentication?
If you are using SQL Server authentication, use:
<add name="ConnectionString"
connectionString="Data Source=127.0.0.1; Initial Catalog=DataBase;Persist Security Info=True;User ID=user; Password=password
then you need to make sure the user has access to the data base and schema that you are using.
If you are using Windows authentication, the use
<add name="ConnectionString"
connectionString="Data Source=127.0.0.1; Initial Catalog=DataBase;Trusted_Connection=Yes;Persist Security Info=True;"/>
then you need to make sure that the user you are using in your App_Pool (the windows account that runs the application) is added as a login/user on the data base and has the rights to run queries.
EDIT
You can use SQL Server Management Studio to do this, step by step instructions can be found here and here
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.