c# samples

M

mp

Somewhere on the microsoft site(have to research where i found them- msdn?)
i got the c# (and vb) samples
When i try to run the create database sample i get the same error from both
c# and vb projects
A first chance exception of type 'System.Data.SqlClient.SqlException'
occurred in System.Data.dll

A network-related or instance-specific error occurred while establishing a
connection to SQL Server. The server was not found or was not accessible.
Verify that the instance name is correct and that SQL Server is configured
to allow remote connections. (provider: Named Pipes Provider, error: 40 -
Could not open a connection to SQL Server)


the readme says vis studio pro required, will express not run these?
Does anyone know what i have to do to get the samples to run?
Thanks

mark
 
P

Peter Duniho

mp said:
[...]
A network-related or instance-specific error occurred while establishing a
connection to SQL Server. The server was not found or was not accessible.
[...]
the readme says vis studio pro required, will express not run these?
Does anyone know what i have to do to get the samples to run?

"the server was not found" implies to me that you haven't started the
server. You can get the SQL Server Express free with the Express
versions of Visual Studio, but it may not be enabled or installed by
default.

Make sure you've actually installed SQL Server Express, and make sure
it's actually running and configured properly to accept connections from
your program.

Pete
 
R

Roger

M

mp

thanks Peter,
off to find tutorial on "Make sure you've actually installed SQL Server
Express, and make sure
it's actually running and configured properly to accept connections from
your program."

mark

Peter Duniho said:
mp said:
[...]
A network-related or instance-specific error occurred while establishing
a
connection to SQL Server. The server was not found or was not accessible.
[...]
the readme says vis studio pro required, will express not run these?
Does anyone know what i have to do to get the samples to run?

"the server was not found" implies to me that you haven't started the
server. You can get the SQL Server Express free with the Express versions
of Visual Studio, but it may not be enabled or installed by default.

Make sure you've actually installed SQL Server Express, and make sure it's
actually running and configured properly to accept connections from your
program.

Pete
 
M

mp

Hi Roger,
Thanks for the link
have read through it but have hit a wall
step 4 says use sql server management studio to set up a server to allow
remote connection

I cant' find any shortcut or exe file that appears to be sql server
management studio
is that only available in visual studio full version?

in sql configuration manager the server is running, but browser and agent
are not, should they be?
i went into agent and tried to start, service start mode was disabled, tried
to set to automatic, got error "not supported"
trying to set to manual, hit apply, have had hourglass cursor for several
minutes now...seems hung
i don't even know what agent is...or browser either
if it ever unfreezes i'll try to mess with other settings


i added the port and sql exceptions to windows firewall,
but when i go to command prompt and type sqlcmd -L there are no servers
listed

all this talk of remote connetions and things being connected through a lan
etc (in various sites and tutorials ive been serarching) confuse me as I'm
just trying to create a simple database on a laptop....no network...no
remote connections

just trying to run a simple c# sample of creating a database, populating
some tables etc....

Is it really this hard using sql server? maybe i should go back to vb6 and
sqllite but wanted to learn the new dotnet way...
thanks for any tips
mark
 
G

Gregory A. Beamer

Somewhere on the microsoft site(have to research where i found them-
msdn?) i got the c# (and vb) samples
When i try to run the create database sample i get the same error from
both c# and vb projects
A first chance exception of type 'System.Data.SqlClient.SqlException'
occurred in System.Data.dll

On SQL Express, do the following:

1. Open SQL Server Configuration Manager
2. Open the SQL Server {version} services
3. Start the SQL Browser Service (optional) - This IS necessary for
remote connections. On a dev box, it is a mixed bag. Set this service to
automatic. With a default install, it is disabled, so you have to enable
first.
4. Open the SQL Server 2005 Network Configuration >> Protocols for
MSSQLSERVER node
5. Turn on Named Pipes and possibly TCP/IP (for remote connections)

Once you do this, restart the SQL Server service.

This should clear up your issues.

NOTE: SQL Server Express is set up so it cannot be connected to remotely
and ONLY uses the Shared Memory protocol. The same is true for SQL
Server in many instances. With this setup, you can generally develop
with Windows Authentication, but anything beyond that gets dicey. The
steps above loosen things up a bit so you can get past this hurdle.

Peace and Grace,

--
Gregory A. Beamer (MVP)

Twitter: @gbworld
Blog: http://gregorybeamer.spaces.live.com

*******************************************
| Think outside the box! |
*******************************************
 
G

Gregory A. Beamer

Make sure you've actually installed SQL Server Express, and make sure
it's actually running and configured properly to accept connections from
your program.

Configuration is most likely the right call, as configuration is what gets
most newbs to SQL Server access. SQL Server 2005 and newer are set up with
the browser off (disabled actually, I think) and only Shared Memory
protocol. Express also starts with Windows Authentication only in the
default configuration, which trips many people up.

Peace and Grace,

--
Gregory A. Beamer (MVP)

Twitter: @gbworld
Blog: http://gregorybeamer.spaces.live.com

*******************************************
| Think outside the box! |
*******************************************
 
M

mp

Thanks and apologies for my total complete ignorance on sql server
the only tiny database code I've done in past is create mdb files with
ado/adox
and sqllite files with dhSqlLite
In those scenarios a database is just a file that can be
created/opened/closed/read/written etc
SqlServer appears to be some kind of actively running something...
For a super simple one man use of database (one computer only) is this
perhaps not the right road for me to try to go down?
seems super complex and a steep learning curve as i cant' even run a sample
to see how things work
Should i go back to vb6 and sqllite maybe? or is there something in
sqlserver that makes it worth the learning curve(for a beginner)?
thanks
mark
 
A

Arne Vajhøj

mp said:
Thanks and apologies for my total complete ignorance on sql server
the only tiny database code I've done in past is create mdb files with
ado/adox
and sqllite files with dhSqlLite
In those scenarios a database is just a file that can be
created/opened/closed/read/written etc
SqlServer appears to be some kind of actively running something...
For a super simple one man use of database (one computer only) is this
perhaps not the right road for me to try to go down?
seems super complex and a steep learning curve as i cant' even run a sample
to see how things work
Should i go back to vb6 and sqllite maybe? or is there something in
sqlserver that makes it worth the learning curve(for a beginner)?

For certain simple usages an embedded database is a
more appropriate solution than a database server.

There are plenty of embedded database available for .NET:
- MS Access via OLE DB
- SQLServer CE
- Firebird
- SQLite

Pick what suits you best.

Arne
 
M

mp

Arne Vajhøj said:
For certain simple usages an embedded database is a
more appropriate solution than a database server.

There are plenty of embedded database available for .NET:
- MS Access via OLE DB
- SQLServer CE
- Firebird
- SQLite

Pick what suits you best.

Arne

Thanks for the clarification I didn't know the term embedded, that's what i
need.
will search for samples hitting sqlite with c#net
Thanks
mark
 
A

Arne Vajhøj

mp said:
Thanks for the clarification I didn't know the term embedded, that's what i
need.
will search for samples hitting sqlite with c#net

It is just like any other database.

See below for two code snippets.

Arne

=======================

using System;
using System.Data;

using System.Data.SQLite;

namespace E
{
public class TestClass
{
public static void Main(string[] args)
{
SQLiteConnection con = new SQLiteConnection(@"Data
Source=C:\TestEmb.db;Version=3;Password=hemmeligt;New=True");
con.Open();
SQLiteCommand cre = new SQLiteCommand("CREATE TABLE tbl (id
INTEGER NOT NULL, txt NVARCHAR(50), PRIMARY KEY(id))", con);
cre.ExecuteNonQuery();
for(int i = 0; i < 3; i++)
{
SQLiteCommand ins = new SQLiteCommand("INSERT INTO tbl
VALUES(" + i + ",'Test" + i + "')", con);
ins.ExecuteNonQuery();
}
con.Close();
}
}
}

using System;
using System.Data;
using System.Data.SQLite;

namespace E
{
public class TestClass
{
public static void Main(string[] args)
{
SQLiteConnection con = new SQLiteConnection(@"Data
Source=C:\TestEmb.db;Version=3;Password=hemmeligt");
con.Open();
SQLiteCommand sel = new SQLiteCommand("SELECT * FROM tbl",
con);
SQLiteDataReader rdr = sel.ExecuteReader();
while(rdr.Read())
{
Console.WriteLine((long)rdr[0] + " " + (string)rdr[1]);
}
rdr.Close();
con.Close();
}
}
}
 
M

mp

Arne Vajhøj said:
It is just like any other database.

See below for two code snippets.

Arne

=======================
snip

awesome, thanks
so ms has incorporated sqlite into it's own framework?!? very surprised
Does that mean I still am using the sqlite dll(sqlite35_engine.dll) or is
that just a com thing and dot net has it's own built in version>?

mark
 
A

Arne Vajhøj

so ms has incorporated sqlite into it's own framework?!? very surprised
Does that mean I still am using the sqlite dll(sqlite35_engine.dll) or is
that just a com thing and dot net has it's own built in version>?

No.

You need to download an SQLite for .NET kit.

I think I used:

http://sourceforge.net/projects/sqlite-dotnet2/files/SQLite for ADO.NET 2.0/

But this provider is following ADO.NET convention, so it is
very natural for any .NET developer to use.

Arne
 
G

Gregory A. Beamer

Should i go back to vb6 and sqllite maybe? or is there something in
sqlserver that makes it worth the learning curve(for a beginner)?
thanks

The problems you are having are a one time setup, so I don't think you
have to scrap SQL Server necessarily. But, as others have stated in this
thread, it might be wise to have an embedded database. It really depends
on the scope of your application.

In many ways, SQL Server is better for the multi-user scenario. If this
is a single user on a single machine, you might be better to use a
different database.

Options:
sqllite
sql server compact
Access
{others}

There are .NET wrappers for SQLLite, etc, so this does not necesitate
going back to COM based programming to solve the database problem.

peace and grace,

--
Gregory A. Beamer (MVP)

Twitter: @gbworld
Blog: http://gregorybeamer.spaces.live.com

*******************************************
| Think outside the box! |
*******************************************
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top