Showing posts with label vs2005. Show all posts
Showing posts with label vs2005. Show all posts

Sunday, February 12, 2012

Adding an sql table through VS2005

Hi,

Currently I am able to check for and add a column to an SQL database using this:

Dim connectionstring As String = My.Settings.ConnectionString

Dim eSQL As String = ""

Using connection As New System.Data.SqlClient.SqlConnection(connectionstring)

Dim cmd As New System.Data.SqlClient.SqlCommand(eSQL, connection)

connection.Open()

eSQL = "IF NOT EXISTS (SELECT * FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_SCHEMA = 'dbo' AND TABLE_NAME = 'Client' AND COLUMN_NAME = 'Company' ) " _

& "BEGIN " _

& "ALTER TABLE [Client] " _

& "ADD Company int " _

& "END "

cmd.CommandText = eSQL

cmd.ExecuteNonQuery()

End Using

I would now like to add a completely new table with two columns to the same database. What syntax would I use?

hi,

GraemeP wrote:

Hi,

I would now like to add a completely new table with two columns to the same database. What syntax would I use?

eSQL = "IF NOT EXISTS (SELECT * FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_SCHEMA = 'dbo' AND TABLE_NAME = 'Client' AND TABLE_TYPE = 'BASE TABLE' ) " _

& "BEGIN " _

& "CREATE TABLE [Client] (" _

& "Company int NOT NULL PRIMARY KEY," _

& "Name varchar(100) NOT NULL DEFAULT 'new company');" _

& "END;"

regards

|||Perfect - thanks!|||

Hi,

I'm getting on fine adding tables and fields programmatically to an SQL database, however I now want to add a view in the same way.

Is this possible, if so would appreciate some sample code.

|||

hi,

GraemeP wrote:

Hi,

I'm getting on fine adding tables and fields programmatically to an SQL database, however I now want to add a view in the same way.

Is this possible, if so would appreciate some sample code.

the very same pattern is not possible for views, as the CREATE VIE statement must be the first in it's own batch... typically you'll overcome this problem dropping the view, if existing like

SET NOCOUNT ON;

USE tempdb;

GO

CREATE VIEW dbo.v1 AS

SELECT 1 AS [ColX];

GO

IF OBJECT_ID('dbo.v1') IS NOT NULL BEGIN

PRINT 'drop';

DROP VIEW dbo.v1;

END;

GO

CREATE VIEW dbo.v1 AS

SELECT 1 AS [ColX];

GO

DROP VIEW dbo.v1;

but this method has gotchas.. all permissions eventually set are gone when the objec is dropped..

regards

Adding an sql table through VS2005

Hi,

Currently I am able to check for and add a column to an SQL database using this:

Dim connectionstring As String = My.Settings.ConnectionString

Dim eSQL As String = ""

Using connection As New System.Data.SqlClient.SqlConnection(connectionstring)

Dim cmd As New System.Data.SqlClient.SqlCommand(eSQL, connection)

connection.Open()

eSQL = "IF NOT EXISTS (SELECT * FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_SCHEMA = 'dbo' AND TABLE_NAME = 'Client' AND COLUMN_NAME = 'Company' ) " _

& "BEGIN " _

& "ALTER TABLE [Client] " _

& "ADD Company int " _

& "END "

cmd.CommandText = eSQL

cmd.ExecuteNonQuery()

End Using

I would now like to add a completely new table with two columns to the same database. What syntax would I use?

hi,

GraemeP wrote:

Hi,

I would now like to add a completely new table with two columns to the same database. What syntax would I use?

eSQL = "IF NOT EXISTS (SELECT * FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_SCHEMA = 'dbo' AND TABLE_NAME = 'Client' AND TABLE_TYPE = 'BASE TABLE' ) " _

& "BEGIN " _

& "CREATE TABLE [Client] (" _

& "Company int NOT NULL PRIMARY KEY," _

& "Name varchar(100) NOT NULL DEFAULT 'new company');" _

& "END;"

regards

|||Perfect - thanks!|||

Hi,

I'm getting on fine adding tables and fields programmatically to an SQL database, however I now want to add a view in the same way.

Is this possible, if so would appreciate some sample code.

|||

hi,

GraemeP wrote:

Hi,

I'm getting on fine adding tables and fields programmatically to an SQL database, however I now want to add a view in the same way.

Is this possible, if so would appreciate some sample code.

the very same pattern is not possible for views, as the CREATE VIE statement must be the first in it's own batch... typically you'll overcome this problem dropping the view, if existing like

SET NOCOUNT ON; USE tempdb; GO CREATE VIEW dbo.v1 AS SELECT 1 AS [ColX]; GO IF OBJECT_ID('dbo.v1') IS NOT NULL BEGIN PRINT 'drop'; DROP VIEW dbo.v1; END; GO CREATE VIEW dbo.v1 AS SELECT 1 AS [ColX]; GO DROP VIEW dbo.v1;

but this method has gotchas.. all permissions eventually set are gone when the objec is dropped..

regards

Adding an SQL Server database to a Websolution

Dear Forum

I really hope someone can help me with the following - it's eating me up.

I'm creating a website in VS2005 and want to add an SQL Server database to the Solution, og I've created a subfolder to the App_Data folder called Database. Now when I click Add New Item and choose SQL database in the Add New Item dialog box I get the following error message

Connections to SQL Server files (*.mdf) require SQL Server Express to function properly. Please verify installation of the component or download from the URL: http://go.microsoft.com/fwlink/?LinkId49251

Now at some point in the past I installed Visual Basic, Visual Web developer and SQL Server express edition, but when I got hold of VS2005 Professional Edition I carefully made sure that all Express version of any VS software was uninstalled beforehand. So now I have only VS2005 Professional Edition and SQL Server 2005 Developer Edition (32 bit) installed on my computer.

I have checked all the environment settings, and can't find a single thing that should point to SQL Server Express Edition.

I would really appriciate if you could give me a helping hand before I loose my sanity.

Thanks a hole bunch.

Tina

My guess is that is because the purpose of placing mdf files in the app_data folder is to attach them to a SQL Server instance and out of the box you cannot attach mdf files to SQL Server except for the Express edition but it is possible to attach mdf files to any edition of SQL Server but it is not recommended to enable this feature on Servers.

There is an article on the MSDN Library I know of that explains how to enable this feature but I cannot seem to find it, as I recall it, you had to start the mssqlserver with the -express argument, but I am not sure about this.

|||

Also I have the same problem and I have resolve it installing sql express 2005 (your link dont work correctly)

you can download sql 2005 form the following link

http://go.microsoft.com/fwlink/?LinkId=49251

Microsoft SQL Server 2005 Express Edition

http://www.microsoft.com/downloads/details.aspx?familyid=220549b5-0b07-4448-8848-dcc397514b41&displaylang=en

|||

If I am not mistaken the developer edition of SQL Server 2005 does not support hosting a database.

You can download SQL Server 2005 express and create an instance of a database using that application.

Once the database has been created inside SQL Server 2005 (IF Developer works all the more power to you). You can then establish a connection within Visual Studio 2005 to that database in order to use in your projects.

Hope this helps.

Chris McNear

Adding an SQL Server database to a Websolution

Dear Forum

I really hope someone can help me with the following - it's eating me up.

I'm creating a website in VS2005 and want to add an SQL Server database to the Solution, og I've created a subfolder to the App_Data folder called Database. Now when I click Add New Item and choose SQL database in the Add New Item dialog box I get the following error message

Connections to SQL Server files (*.mdf) require SQL Server Express to function properly. Please verify installation of the component or download from the URL: http://go.microsoft.com/fwlink/?LinkId49251

Now at some point in the past I installed Visual Basic, Visual Web developer and SQL Server express edition, but when I got hold of VS2005 Professional Edition I carefully made sure that all Express version of any VS software was uninstalled beforehand. So now I have only VS2005 Professional Edition and SQL Server 2005 Developer Edition (32 bit) installed on my computer.

I have checked all the environment settings, and can't find a single thing that should point to SQL Server Express Edition.

I would really appriciate if you could give me a helping hand before I loose my sanity.

Thanks a hole bunch.

Tina

My guess is that is because the purpose of placing mdf files in the app_data folder is to attach them to a SQL Server instance and out of the box you cannot attach mdf files to SQL Server except for the Express edition but it is possible to attach mdf files to any edition of SQL Server but it is not recommended to enable this feature on Servers.

There is an article on the MSDN Library I know of that explains how to enable this feature but I cannot seem to find it, as I recall it, you had to start the mssqlserver with the -express argument, but I am not sure about this.

|||

Also I have the same problem and I have resolve it installing sql express 2005 (your link dont work correctly)

you can download sql 2005 form the following link

http://go.microsoft.com/fwlink/?LinkId=49251

Microsoft SQL Server 2005 Express Edition

http://www.microsoft.com/downloads/details.aspx?familyid=220549b5-0b07-4448-8848-dcc397514b41&displaylang=en

|||

If I am not mistaken the developer edition of SQL Server 2005 does not support hosting a database.

You can download SQL Server 2005 express and create an instance of a database using that application.

Once the database has been created inside SQL Server 2005 (IF Developer works all the more power to you). You can then establish a connection within Visual Studio 2005 to that database in order to use in your projects.

Hope this helps.

Chris McNear