473,396 Members | 2,158 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

playing with ASP.NET & SqlServer express

I never really use SQLExpress before...
Anyway I'm trying to something a bit 'advanced' and I'm failing miserably.

I have written a BlogEngin a while ago using SqlServer & ASP.NET 2.0 Beta 2 and try to rewrite it from scratch (and copy paste). It's hard as I forgot all about ASP.NET...

Anyway, right now I'm trying to open a connection to and SqlServerExpress file. To make things a bit more difficult this file might not exist (as a matter of fact it doesn't exist now, it might be the reason of my trouble).

I'm trying to create a connection like that:
===
public static SqlConnection GetConnection(string filename)
{
string connString = @"Data Source=.\SQLEXPRESS;AttachDbFileName=|DataDirector y|{0}.mdf;Integrated Security=True;User Instance=True";
connString = string.Format(connString, filename);
SqlConnection sqlc = new SqlConnection(filename); // <= exception here
return sqlc;
}
===
It fails with "Format of the initialization string does not conform to specification starting at index 0."

Then, somehow, I would like to detect if the DB exist or not and create the database automatically (I have the SQL creation script ready).

How could I do that?
Is my connection string alright? (except for the fact the file doesn't exist...)
How could I check if the file exist? Is something like:
File.Exists(MapPath(ResolveUrl(string.Format("~/App_Data/{0}.mdf", filename"))))
a good idea?

How could I create the required connection to call the creation script if the database/file doesn'ty exist?
Dec 30 '05 #1
1 1421
shouldn't you be passing connString into the code?

Personally, instead of checking for the database file, I'd simply connect to MASTER, and see if the database exists

select * from sysdatabases
where name = 'whatever'
you can returna value, if it exists, and run the creation script if not.

Karl

--
MY ASP.Net tutorials
http://www.openmymind.net/
http://openmymind.net/redirector.aspx?documentId=51 - Learn about AJAX!

"Lloyd Dupont" <net.galador@ld> wrote in message news:%2****************@TK2MSFTNGP09.phx.gbl...
I never really use SQLExpress before...
Anyway I'm trying to something a bit 'advanced' and I'm failing miserably.

I have written a BlogEngin a while ago using SqlServer & ASP.NET 2.0 Beta 2 and try to rewrite it from scratch (and copy paste). It's hard as I forgot all about ASP.NET...

Anyway, right now I'm trying to open a connection to and SqlServerExpress file. To make things a bit more difficult this file might not exist (as a matter of fact it doesn't exist now, it might be the reason of my trouble).

I'm trying to create a connection like that:
===
public static SqlConnection GetConnection(string filename)
{
string connString = @"Data Source=.\SQLEXPRESS;AttachDbFileName=|DataDirector y|{0}.mdf;Integrated Security=True;User Instance=True";
connString = string.Format(connString, filename);
SqlConnection sqlc = new SqlConnection(filename); // <= exception here
return sqlc;
}
===
It fails with "Format of the initialization string does not conform to specification starting at index 0."

Then, somehow, I would like to detect if the DB exist or not and create the database automatically (I have the SQL creation script ready).

How could I do that?
Is my connection string alright? (except for the fact the file doesn't exist...)
How could I check if the file exist? Is something like:
File.Exists(MapPath(ResolveUrl(string.Format("~/App_Data/{0}.mdf", filename"))))
a good idea?

How could I create the required connection to call the creation script if the database/file doesn'ty exist?
Dec 30 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: how can i insert a image to SQLServer? | last post by:
I want to insert some strings and images which from richTextBox into SQLServer. I could insert it into SQLServer,such as follows: FileStream s=new FileStream...
2
by: saroxonline76 | last post by:
Dear all, I installed Visual Basic 2005 Express and SqlServer Express. I tried some features of both of them but I'm not able to connect a databse through a network. To explain, I have two...
1
by: kt | last post by:
I am not sure if this is the proper place to put this query but we have had no success elsewhere. Creating a website using VS 2005 and using the "ASP .Net Configutration" tool updates the...
3
by: Dan Sikorsky | last post by:
Can I use SQLServer 2000 with ASP.NET 2.0 instead of SQLServer 2005, and use the .Net 2.0 Membership functionality? I've setup my Login page, controls, etc., and now it's time to use the Web...
2
by: dgk | last post by:
I'm using the standard provider for membership which is SQLServer Express. After deploying the app to our server, login fails because of an SQL problem. I'm guessing that the problem is that the...
6
by: Noble | last post by:
I am getting ready to write a shareware app in .Net using C# (actually convert a VB shareware). I currently use a third party dll for the data management. It is called the Tsunami Record Manager. I...
4
by: GaryDean | last post by:
I have a 2.0 Website application in the dev environment that uses a SQL Server 2005 DB and also uses the authentication controls and classes that automatically use SQLServer Express. It all works...
7
by: Academia | last post by:
I was told that SqlServer express should get installed when VS2008Pro is installed (that is it is on the same DVD). I had a couple of errors during vs2008's installation and I don't see any...
6
by: ad | last post by:
How can I detect if my computer have installed SQLServer 2005 or SQLServer 2005 Express with program like c# or VB.NNET?
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.