Showing posts with label named. Show all posts
Showing posts with label named. Show all posts

Sunday, February 26, 2012

error with connection with SQL SERVER

Hi

I am developing web application.

I have connected my app. with sql server using web.config as code given below using Named pipe connection

<appSettings>
<add key="constring" value="Server=ebserver;UID=sa;database=Airport-Clearance;Integrated Security=SSPI;network library=dbnmpntw;" />
</appSettings
After than i have added a new CLASS in my app.
in that, I have written as given below code.

public SqlConnection GetConnection()
{
System.Configuration.AppSettingsReader objApp = new System.Configuration.AppSettingsReader ();
SqlConnection sqlconn = new SqlConnection ();
sqlconn.ConnectionString = Convert.ToString(objApp.GetValue("constring", typeof(string)));
return sqlconn ;
}

Finally, In load event of form, I have written as below code.

Class1 objcs = new Class1() ;
SqlConnection sqlconn = objcs.GetConnection ();
SqlDataAdapter filling = new SqlDataAdapter("select * from Airport",sqlconn);
DataSet ds = new DataSet();
sqlconn.Open();
//filling.Fill(ds,"Airport");

//DataGrid dg = new DataGrid();
dg.DataSource = ds.Tables["Airport"];
dg.DataBind();
//Do what ever
sqlconn.Close ();

When i run this application

It gives error like

provider: Named Pipes Provider, error: 40 - Could not open a connection to SQL Server)

If i use try catch then it doesnt display any error.but Even it doesnt display datagrid on form.

Please give me solution.

Even how to run app. line by line as we run in VB using F8.

Reply please,

Regards,
ASIFTry this instead (assuming you're not using beta version):

public SqlConnection GetConnection()
{
SqlConnection sqlconn = new SqlConnection ();
sqlconn.ConnectionString = System.Configuration.ConfigurationManager.ConnectionStrings["constring"].ConnectionString;
return sqlconn ;
}

Wednesday, February 15, 2012

Error while creating a new view

I get the message "There is already an object named 'xxx' in the
database. I was creating a new view and had an error on it. I fixed the
error and resubmitted the create view and I received this error
message. I tried to find the view but it was not there. It must have
created an object with that name somewhere in the data base. How do I
find the object and remove it?I forgot to mention that I am using SQL Server 2000.|||I forgot to mention that I am using SQL Server 2000.|||Add this at the top before your Create View statement:
IF EXISTS (SELECT TABLE_NAME FROM INFORMATION_SCHEMA.VIEWS
WHERE TABLE_NAME = 'thenameofyourview')
DROP VIEW thenameofyourview
GO
"moonflower" <Jack_S_Owens@.hotmail.com> wrote in message
news:1132166124.934501.74210@.f14g2000cwb.googlegroups.com...
>I get the message "There is already an object named 'xxx' in the
> database. I was creating a new view and had an error on it. I fixed the
> error and resubmitted the create view and I received this error
> message. I tried to find the view but it was not there. It must have
> created an object with that name somewhere in the data base. How do I
> find the object and remove it?
>|||When I put the IF statement before the Create View statement in the SQL
QueryAnalyzer program I get an error message " CREATE VIEW must be the
first statement in a query batch". Where can I run these statements and
not get the new error message?|||"moonflower" <Jack_S_Owens@.hotmail.com> wrote in message
news:1132166124.934501.74210@.f14g2000cwb.googlegroups.com...
>I get the message "There is already an object named 'xxx' in the
> database. I was creating a new view and had an error on it. I fixed the
> error and resubmitted the create view and I received this error
> message. I tried to find the view but it was not there. It must have
> created an object with that name somewhere in the data base. How do I
> find the object and remove it?
>
IF object_ID('xxx') is not null
exec ( 'drop view xxx' )
go
create view xxx
as
select 1234
GO
How are you looking for the view ?
Have you hit REFRESH ?
S.|||Use the IF before the DROP VIEW command. Then execute CREATE VIEW in its own
batch (after GO).
Tibor Karaszi, SQL Server MVP
http://www.karaszi.com/sqlserver/default.asp
http://www.solidqualitylearning.com/
"moonflower" <Jack_S_Owens@.hotmail.com> wrote in message
news:1132179017.603657.268500@.g49g2000cwa.googlegroups.com...
> When I put the IF statement before the Create View statement in the SQL
> QueryAnalyzer program I get an error message " CREATE VIEW must be the
> first statement in a query batch". Where can I run these statements and
> not get the new error message?
>